2007-06-24 20:45:48 -04:00
|
|
|
/* -*-c-*- */
|
2006-12-31 10:02:22 -05:00
|
|
|
/*
|
|
|
|
* included by eval.c
|
|
|
|
*/
|
|
|
|
|
2018-01-06 23:57:04 -05:00
|
|
|
#define write_warn(str, x) \
|
|
|
|
(NIL_P(str) ? warn_print(x) : (void)rb_str_cat_cstr(str, x))
|
|
|
|
#define write_warn2(str, x, l) \
|
|
|
|
(NIL_P(str) ? warn_print2(x, l) : (void)rb_str_cat(str, x, l))
|
2016-05-12 14:12:46 -04:00
|
|
|
#ifdef HAVE_BUILTIN___BUILTIN_CONSTANT_P
|
Use RB_GNUC_EXTENSION_BLOCK instead of __extension__
* include/ruby/defines.h (RB_GNUC_EXTENSION, RB_GNUC_EXTENSION_BLOCK):
macros for skipping __extension__ on non-GCC compilers.
* eval_error.c (warn_print): use RB_GNUC_EXTENSION_BLOCK instead of
__extension__ because __extension__ is a GNU extension.
Fix compile error on Solaris 10 with Oracle Solaris Studio 12.x.
[Bug #12397] [ruby-dev:49629].
* internal.h (rb_fstring_cstr, rb_fstring_enc_cstr): ditto
* include/ruby/encoding.h (rb_enc_str_new, rb_enc_str_new_cstr): ditto
* include/ruby/intern.h (rb_str_new, rb_str_new_cstr,
rb_usascii_str_new, rb_utf8_str_new, rb_tainted_str_new_cstr,
rb_usascii_str_new_cstr, rb_utf8_str_new_cstr,
rb_external_str_new_cstr, rb_locale_str_new_cstr,
rb_str_buf_new_cstr, rb_str_cat_cstr, rb_exc_new_cstr): ditto
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55082 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-20 08:29:06 -04:00
|
|
|
#define warn_print(x) RB_GNUC_EXTENSION_BLOCK( \
|
2016-03-06 03:34:50 -05:00
|
|
|
(__builtin_constant_p(x)) ? \
|
|
|
|
rb_write_error2((x), (long)strlen(x)) : \
|
Use RB_GNUC_EXTENSION_BLOCK instead of __extension__
* include/ruby/defines.h (RB_GNUC_EXTENSION, RB_GNUC_EXTENSION_BLOCK):
macros for skipping __extension__ on non-GCC compilers.
* eval_error.c (warn_print): use RB_GNUC_EXTENSION_BLOCK instead of
__extension__ because __extension__ is a GNU extension.
Fix compile error on Solaris 10 with Oracle Solaris Studio 12.x.
[Bug #12397] [ruby-dev:49629].
* internal.h (rb_fstring_cstr, rb_fstring_enc_cstr): ditto
* include/ruby/encoding.h (rb_enc_str_new, rb_enc_str_new_cstr): ditto
* include/ruby/intern.h (rb_str_new, rb_str_new_cstr,
rb_usascii_str_new, rb_utf8_str_new, rb_tainted_str_new_cstr,
rb_usascii_str_new_cstr, rb_utf8_str_new_cstr,
rb_external_str_new_cstr, rb_locale_str_new_cstr,
rb_str_buf_new_cstr, rb_str_cat_cstr, rb_exc_new_cstr): ditto
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55082 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-20 08:29:06 -04:00
|
|
|
rb_write_error(x) \
|
|
|
|
)
|
2016-03-06 03:34:50 -05:00
|
|
|
#else
|
2006-12-31 10:02:22 -05:00
|
|
|
#define warn_print(x) rb_write_error(x)
|
2016-03-06 03:34:50 -05:00
|
|
|
#endif
|
2017-12-12 06:47:16 -05:00
|
|
|
|
2010-12-11 23:28:29 -05:00
|
|
|
#define warn_print2(x,l) rb_write_error2((x),(l))
|
2017-12-12 06:47:16 -05:00
|
|
|
|
2017-12-18 10:46:56 -05:00
|
|
|
#define write_warn_str(str,x) NIL_P(str) ? rb_write_error_str(x) : (void)rb_str_concat((str), (x))
|
2013-06-24 09:03:35 -04:00
|
|
|
#define warn_print_str(x) rb_write_error_str(x)
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2016-02-25 07:36:24 -05:00
|
|
|
static VALUE error_pos_str(void);
|
|
|
|
|
2006-12-31 10:02:22 -05:00
|
|
|
static void
|
2017-12-12 06:47:16 -05:00
|
|
|
error_pos(const VALUE str)
|
2016-02-25 07:36:24 -05:00
|
|
|
{
|
2017-12-12 06:47:16 -05:00
|
|
|
VALUE pos = error_pos_str();
|
|
|
|
if (!NIL_P(pos)) {
|
|
|
|
write_warn_str(str, pos);
|
2016-02-25 07:36:24 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
error_pos_str(void)
|
2006-12-31 10:02:22 -05:00
|
|
|
{
|
2015-10-30 21:02:26 -04:00
|
|
|
int sourceline;
|
|
|
|
VALUE sourcefile = rb_source_location(&sourceline);
|
2007-06-24 16:33:04 -04:00
|
|
|
|
2017-11-16 00:35:58 -05:00
|
|
|
if (!NIL_P(sourcefile)) {
|
2013-05-24 18:03:41 -04:00
|
|
|
ID caller_name;
|
2007-06-24 16:33:04 -04:00
|
|
|
if (sourceline == 0) {
|
2016-02-25 07:36:24 -05:00
|
|
|
return rb_sprintf("%"PRIsVALUE": ", sourcefile);
|
2006-12-31 10:02:22 -05:00
|
|
|
}
|
2013-05-24 18:03:41 -04:00
|
|
|
else if ((caller_name = rb_frame_callee()) != 0) {
|
2016-02-25 07:36:24 -05:00
|
|
|
return rb_sprintf("%"PRIsVALUE":%d:in `%"PRIsVALUE"': ",
|
|
|
|
sourcefile, sourceline,
|
|
|
|
rb_id2str(caller_name));
|
2006-12-31 10:02:22 -05:00
|
|
|
}
|
|
|
|
else {
|
2016-02-25 07:36:24 -05:00
|
|
|
return rb_sprintf("%"PRIsVALUE":%d: ", sourcefile, sourceline);
|
2006-12-31 10:02:22 -05:00
|
|
|
}
|
|
|
|
}
|
2016-02-25 07:36:24 -05:00
|
|
|
return Qnil;
|
2006-12-31 10:02:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
set_backtrace(VALUE info, VALUE bt)
|
|
|
|
{
|
2012-05-24 02:09:23 -04:00
|
|
|
ID set_backtrace = rb_intern("set_backtrace");
|
|
|
|
|
|
|
|
if (rb_backtrace_p(bt)) {
|
2012-05-24 02:36:44 -04:00
|
|
|
if (rb_method_basic_definition_p(CLASS_OF(info), set_backtrace)) {
|
2012-05-24 02:09:23 -04:00
|
|
|
rb_exc_set_backtrace(info, bt);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
bt = rb_backtrace_to_str_ary(bt);
|
|
|
|
}
|
|
|
|
}
|
2016-11-13 00:25:53 -05:00
|
|
|
rb_check_funcall(info, set_backtrace, 1, &bt);
|
2006-12-31 10:02:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-10-29 10:06:58 -04:00
|
|
|
error_print(rb_execution_context_t *ec)
|
2016-06-05 20:25:38 -04:00
|
|
|
{
|
2017-10-29 10:06:58 -04:00
|
|
|
rb_ec_error_print(ec, ec->errinfo);
|
2016-06-05 20:25:38 -04:00
|
|
|
}
|
|
|
|
|
2019-01-08 04:08:31 -05:00
|
|
|
static void
|
|
|
|
write_warnq(VALUE out, VALUE str, const char *ptr, long len)
|
|
|
|
{
|
|
|
|
if (NIL_P(out)) {
|
|
|
|
const char *beg = ptr;
|
|
|
|
const long olen = len;
|
|
|
|
for (; len > 0; --len, ++ptr) {
|
|
|
|
unsigned char c = *ptr;
|
2019-01-24 05:10:18 -05:00
|
|
|
switch (c) {
|
|
|
|
case '\n': case '\t': continue;
|
|
|
|
}
|
2019-01-08 04:08:31 -05:00
|
|
|
if (rb_iscntrl(c)) {
|
|
|
|
char buf[5];
|
|
|
|
const char *cc = 0;
|
|
|
|
if (ptr > beg) rb_write_error2(beg, ptr - beg);
|
|
|
|
beg = ptr + 1;
|
|
|
|
cc = ruby_escaped_char(c);
|
|
|
|
if (cc) {
|
|
|
|
rb_write_error2(cc, strlen(cc));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rb_write_error2(buf, snprintf(buf, sizeof(buf), "\\x%02X", c));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (c == '\\') {
|
|
|
|
rb_write_error2(beg, ptr - beg + 1);
|
|
|
|
beg = ptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ptr > beg) {
|
|
|
|
if (beg == RSTRING_PTR(str) && olen == RSTRING_LEN(str))
|
|
|
|
rb_write_error_str(str);
|
|
|
|
else
|
|
|
|
rb_write_error2(beg, ptr - beg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rb_str_cat(out, ptr, len);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-23 03:39:03 -05:00
|
|
|
#define CSI_BEGIN "\033["
|
|
|
|
#define CSI_SGR "m"
|
|
|
|
|
|
|
|
static const char underline[] = CSI_BEGIN"1;4"CSI_SGR;
|
|
|
|
static const char bold[] = CSI_BEGIN"1"CSI_SGR;
|
|
|
|
static const char reset[] = CSI_BEGIN""CSI_SGR;
|
|
|
|
|
2017-02-22 03:50:25 -05:00
|
|
|
static void
|
2018-01-06 23:16:31 -05:00
|
|
|
print_errinfo(const VALUE eclass, const VALUE errat, const VALUE emesg, const VALUE str, int highlight)
|
2006-12-31 10:02:22 -05:00
|
|
|
{
|
2017-02-22 03:50:25 -05:00
|
|
|
const char *einfo = "";
|
|
|
|
long elen = 0;
|
2016-02-25 02:22:01 -05:00
|
|
|
VALUE mesg;
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2017-02-22 03:50:25 -05:00
|
|
|
if (emesg != Qundef) {
|
|
|
|
if (NIL_P(errat) || RARRAY_LEN(errat) == 0 ||
|
|
|
|
NIL_P(mesg = RARRAY_AREF(errat, 0))) {
|
2017-12-12 06:47:16 -05:00
|
|
|
error_pos(str);
|
2017-02-22 03:50:25 -05:00
|
|
|
}
|
|
|
|
else {
|
2017-12-12 06:47:16 -05:00
|
|
|
write_warn_str(str, mesg);
|
|
|
|
write_warn(str, ": ");
|
2017-02-22 03:50:25 -05:00
|
|
|
}
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2017-02-22 03:50:25 -05:00
|
|
|
if (!NIL_P(emesg)) {
|
|
|
|
einfo = RSTRING_PTR(emesg);
|
2017-11-29 06:14:23 -05:00
|
|
|
elen = RSTRING_LEN(emesg);
|
2017-02-22 03:50:25 -05:00
|
|
|
}
|
2006-12-31 10:02:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (eclass == rb_eRuntimeError && elen == 0) {
|
2018-01-06 23:16:31 -05:00
|
|
|
if (highlight) write_warn(str, underline);
|
2018-01-07 00:38:37 -05:00
|
|
|
write_warn(str, "unhandled exception");
|
|
|
|
if (highlight) write_warn(str, reset);
|
|
|
|
write_warn2(str, "\n", 1);
|
2006-12-31 10:02:22 -05:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
VALUE epath;
|
|
|
|
|
|
|
|
epath = rb_class_name(eclass);
|
|
|
|
if (elen == 0) {
|
2018-01-06 23:16:31 -05:00
|
|
|
if (highlight) write_warn(str, underline);
|
2017-12-12 06:47:16 -05:00
|
|
|
write_warn_str(str, epath);
|
2018-01-07 00:38:37 -05:00
|
|
|
if (highlight) write_warn(str, reset);
|
2017-12-12 06:47:16 -05:00
|
|
|
write_warn(str, "\n");
|
2006-12-31 10:02:22 -05:00
|
|
|
}
|
|
|
|
else {
|
2019-07-15 03:51:18 -04:00
|
|
|
/* emesg is a String instance */
|
2016-02-25 07:36:25 -05:00
|
|
|
const char *tail = 0;
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2019-07-15 03:51:18 -04:00
|
|
|
if (highlight) write_warn(str, bold);
|
2006-12-31 10:02:22 -05:00
|
|
|
if (RSTRING_PTR(epath)[0] == '#')
|
|
|
|
epath = 0;
|
2007-08-18 03:44:51 -04:00
|
|
|
if ((tail = memchr(einfo, '\n', elen)) != 0) {
|
2019-01-08 04:08:37 -05:00
|
|
|
write_warnq(str, emesg, einfo, tail - einfo);
|
2006-12-31 10:02:22 -05:00
|
|
|
tail++; /* skip newline */
|
2018-01-07 00:38:37 -05:00
|
|
|
}
|
|
|
|
else {
|
2019-01-08 04:08:37 -05:00
|
|
|
write_warnq(str, emesg, einfo, elen);
|
2006-12-31 10:02:22 -05:00
|
|
|
}
|
|
|
|
if (epath) {
|
2017-12-12 06:47:16 -05:00
|
|
|
write_warn(str, " (");
|
2018-01-06 23:16:31 -05:00
|
|
|
if (highlight) write_warn(str, underline);
|
2017-12-12 06:47:16 -05:00
|
|
|
write_warn_str(str, epath);
|
2018-01-07 00:38:37 -05:00
|
|
|
if (highlight) {
|
|
|
|
write_warn(str, reset);
|
|
|
|
write_warn(str, bold);
|
|
|
|
}
|
|
|
|
write_warn2(str, ")", 1);
|
2018-01-06 23:16:31 -05:00
|
|
|
if (highlight) write_warn(str, reset);
|
2018-01-07 00:38:37 -05:00
|
|
|
write_warn2(str, "\n", 1);
|
2006-12-31 10:02:22 -05:00
|
|
|
}
|
2018-03-12 23:48:56 -04:00
|
|
|
if (tail && einfo+elen > tail) {
|
|
|
|
if (!highlight) {
|
2019-01-08 04:08:37 -05:00
|
|
|
write_warnq(str, emesg, tail, einfo+elen-tail);
|
2018-03-12 23:48:56 -04:00
|
|
|
if (einfo[elen-1] != '\n') write_warn2(str, "\n", 1);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
elen -= tail - einfo;
|
|
|
|
einfo = tail;
|
|
|
|
while (elen > 0) {
|
|
|
|
tail = memchr(einfo, '\n', elen);
|
|
|
|
if (!tail || tail > einfo) {
|
|
|
|
write_warn(str, bold);
|
2019-01-08 04:08:37 -05:00
|
|
|
write_warnq(str, emesg, einfo, tail ? tail-einfo : elen);
|
2018-03-12 23:48:56 -04:00
|
|
|
write_warn(str, reset);
|
|
|
|
if (!tail) {
|
|
|
|
write_warn2(str, "\n", 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elen -= tail - einfo;
|
|
|
|
einfo = tail;
|
|
|
|
do ++tail; while (tail < einfo+elen && *tail == '\n');
|
2019-01-08 04:08:37 -05:00
|
|
|
write_warnq(str, emesg, einfo, tail-einfo);
|
2018-03-12 23:48:56 -04:00
|
|
|
elen -= tail - einfo;
|
|
|
|
einfo = tail;
|
|
|
|
}
|
2018-01-07 00:38:37 -05:00
|
|
|
}
|
|
|
|
}
|
2018-03-12 23:40:10 -04:00
|
|
|
else if (!epath) {
|
2018-01-07 00:38:37 -05:00
|
|
|
write_warn2(str, "\n", 1);
|
2006-12-31 10:02:22 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-02-22 03:50:25 -05:00
|
|
|
}
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2017-02-22 03:50:25 -05:00
|
|
|
static void
|
2017-12-12 06:47:16 -05:00
|
|
|
print_backtrace(const VALUE eclass, const VALUE errat, const VALUE str, int reverse)
|
2017-02-22 03:50:25 -05:00
|
|
|
{
|
2006-12-31 10:02:22 -05:00
|
|
|
if (!NIL_P(errat)) {
|
|
|
|
long i;
|
|
|
|
long len = RARRAY_LEN(errat);
|
2007-06-19 19:27:47 -04:00
|
|
|
int skip = eclass == rb_eSysStackError;
|
2017-05-19 03:12:45 -04:00
|
|
|
const int threshold = 1000000000;
|
2018-11-15 04:03:03 -05:00
|
|
|
int width = (len <= 1) ? INT_MIN : ((int)log10((double)(len > threshold ?
|
2017-05-19 03:12:45 -04:00
|
|
|
((len - 1) / threshold) :
|
|
|
|
len - 1)) +
|
2017-05-19 03:34:05 -04:00
|
|
|
(len < threshold ? 0 : 9) + 1);
|
2009-02-22 09:23:33 -05:00
|
|
|
|
2006-12-31 10:02:22 -05:00
|
|
|
#define TRACE_MAX (TRACE_HEAD+TRACE_TAIL+5)
|
|
|
|
#define TRACE_HEAD 8
|
|
|
|
#define TRACE_TAIL 5
|
|
|
|
|
|
|
|
for (i = 1; i < len; i++) {
|
2017-02-22 03:50:25 -05:00
|
|
|
VALUE line = RARRAY_AREF(errat, reverse ? len - i : i);
|
2013-06-11 02:57:04 -04:00
|
|
|
if (RB_TYPE_P(line, T_STRING)) {
|
2017-12-12 06:47:16 -05:00
|
|
|
VALUE bt = rb_str_new_cstr("\t");
|
|
|
|
if (reverse) rb_str_catf(bt, "%*ld: ", width, len - i);
|
|
|
|
write_warn_str(str, rb_str_catf(bt, "from %"PRIsVALUE"\n", line));
|
2006-12-31 10:02:22 -05:00
|
|
|
}
|
2007-06-19 19:27:47 -04:00
|
|
|
if (skip && i == TRACE_HEAD && len > TRACE_MAX) {
|
2017-12-12 06:47:16 -05:00
|
|
|
write_warn_str(str, rb_sprintf("\t ... %ld levels...\n",
|
2016-02-25 07:36:24 -05:00
|
|
|
len - TRACE_HEAD - TRACE_TAIL));
|
2006-12-31 10:02:22 -05:00
|
|
|
i = len - TRACE_TAIL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-02-22 03:50:25 -05:00
|
|
|
}
|
|
|
|
|
2018-10-27 17:45:30 -04:00
|
|
|
VALUE rb_get_message(VALUE exc);
|
|
|
|
|
2018-12-22 02:14:14 -05:00
|
|
|
static int
|
|
|
|
shown_cause_p(VALUE cause, VALUE *shown_causes)
|
|
|
|
{
|
|
|
|
VALUE shown = *shown_causes;
|
|
|
|
if (!shown) {
|
|
|
|
*shown_causes = shown = rb_obj_hide(rb_ident_hash_new());
|
|
|
|
}
|
|
|
|
if (rb_hash_has_key(shown, cause)) return TRUE;
|
|
|
|
rb_hash_aset(shown, cause, Qtrue);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2018-10-27 17:45:30 -04:00
|
|
|
static void
|
2018-12-22 02:14:14 -05:00
|
|
|
show_cause(VALUE errinfo, VALUE str, VALUE highlight, VALUE reverse, VALUE *shown_causes)
|
2018-10-27 17:45:30 -04:00
|
|
|
{
|
|
|
|
VALUE cause = rb_attr_get(errinfo, id_cause);
|
2018-12-22 02:14:14 -05:00
|
|
|
if (!NIL_P(cause) && rb_obj_is_kind_of(cause, rb_eException) &&
|
|
|
|
!shown_cause_p(cause, shown_causes)) {
|
2018-10-27 17:45:30 -04:00
|
|
|
volatile VALUE eclass = CLASS_OF(cause);
|
|
|
|
VALUE errat = rb_get_backtrace(cause);
|
|
|
|
VALUE emesg = rb_get_message(cause);
|
|
|
|
if (reverse) {
|
2018-12-22 02:14:14 -05:00
|
|
|
show_cause(cause, str, highlight, reverse, shown_causes);
|
2018-10-27 19:13:34 -04:00
|
|
|
print_backtrace(eclass, errat, str, TRUE);
|
2018-10-27 17:45:30 -04:00
|
|
|
print_errinfo(eclass, errat, emesg, str, highlight!=0);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
print_errinfo(eclass, errat, emesg, str, highlight!=0);
|
2018-10-27 19:13:34 -04:00
|
|
|
print_backtrace(eclass, errat, str, FALSE);
|
2018-12-22 02:14:14 -05:00
|
|
|
show_cause(cause, str, highlight, reverse, shown_causes);
|
2018-10-27 17:45:30 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-22 03:50:25 -05:00
|
|
|
void
|
2018-04-11 04:03:43 -04:00
|
|
|
rb_error_write(VALUE errinfo, VALUE emesg, VALUE errat, VALUE str, VALUE highlight, VALUE reverse)
|
2017-02-22 03:50:25 -05:00
|
|
|
{
|
2018-04-11 04:03:43 -04:00
|
|
|
volatile VALUE eclass;
|
2018-12-22 02:14:14 -05:00
|
|
|
VALUE shown_causes = 0;
|
2017-02-22 03:50:25 -05:00
|
|
|
|
|
|
|
if (NIL_P(errinfo))
|
|
|
|
return;
|
|
|
|
|
2017-12-12 06:47:16 -05:00
|
|
|
if (errat == Qundef) {
|
2017-02-22 03:50:25 -05:00
|
|
|
errat = Qnil;
|
|
|
|
}
|
2018-04-11 04:03:43 -04:00
|
|
|
eclass = CLASS_OF(errinfo);
|
2018-02-23 03:39:03 -05:00
|
|
|
if (NIL_P(reverse) || NIL_P(highlight)) {
|
|
|
|
VALUE tty = (VALUE)rb_stderr_tty_p();
|
|
|
|
if (NIL_P(reverse)) reverse = tty;
|
|
|
|
if (NIL_P(highlight)) highlight = tty;
|
|
|
|
}
|
|
|
|
if (reverse) {
|
|
|
|
static const char traceback[] = "Traceback "
|
|
|
|
"(most recent call last):\n";
|
|
|
|
const int bold_part = rb_strlen_lit("Traceback");
|
|
|
|
char buff[sizeof(traceback)+sizeof(bold)+sizeof(reset)-2], *p = buff;
|
|
|
|
const char *msg = traceback;
|
|
|
|
long len = sizeof(traceback) - 1;
|
|
|
|
if (highlight) {
|
|
|
|
#define APPEND(s, l) (memcpy(p, s, l), p += (l))
|
|
|
|
APPEND(bold, sizeof(bold)-1);
|
|
|
|
APPEND(traceback, bold_part);
|
|
|
|
APPEND(reset, sizeof(reset)-1);
|
|
|
|
APPEND(traceback + bold_part, sizeof(traceback)-bold_part-1);
|
|
|
|
#undef APPEND
|
|
|
|
len = p - (msg = buff);
|
|
|
|
}
|
|
|
|
write_warn2(str, msg, len);
|
2018-12-22 02:14:14 -05:00
|
|
|
show_cause(errinfo, str, highlight, reverse, &shown_causes);
|
2017-12-12 06:47:16 -05:00
|
|
|
print_backtrace(eclass, errat, str, TRUE);
|
2018-02-23 03:39:03 -05:00
|
|
|
print_errinfo(eclass, errat, emesg, str, highlight!=0);
|
2017-02-22 03:50:25 -05:00
|
|
|
}
|
|
|
|
else {
|
2018-02-23 03:39:03 -05:00
|
|
|
print_errinfo(eclass, errat, emesg, str, highlight!=0);
|
2017-12-12 06:47:16 -05:00
|
|
|
print_backtrace(eclass, errat, str, FALSE);
|
2018-12-22 02:14:14 -05:00
|
|
|
show_cause(errinfo, str, highlight, reverse, &shown_causes);
|
2017-02-22 03:50:25 -05:00
|
|
|
}
|
2017-12-12 06:47:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
rb_ec_error_print(rb_execution_context_t * volatile ec, volatile VALUE errinfo)
|
|
|
|
{
|
2018-10-19 16:56:10 -04:00
|
|
|
volatile uint8_t raised_flag = ec->raised_flag;
|
2018-01-02 01:42:03 -05:00
|
|
|
volatile VALUE errat = Qundef;
|
2018-04-11 04:03:43 -04:00
|
|
|
volatile VALUE emesg = Qundef;
|
2017-12-12 06:47:16 -05:00
|
|
|
|
|
|
|
if (NIL_P(errinfo))
|
|
|
|
return;
|
|
|
|
rb_ec_raised_clear(ec);
|
|
|
|
|
|
|
|
EC_PUSH_TAG(ec);
|
|
|
|
if (EC_EXEC_TAG() == TAG_NONE) {
|
|
|
|
errat = rb_get_backtrace(errinfo);
|
|
|
|
}
|
2018-04-11 04:03:43 -04:00
|
|
|
if (emesg == Qundef) {
|
|
|
|
emesg = Qnil;
|
|
|
|
emesg = rb_get_message(errinfo);
|
|
|
|
}
|
2017-12-12 06:47:16 -05:00
|
|
|
|
2018-04-11 04:03:43 -04:00
|
|
|
rb_error_write(errinfo, emesg, errat, Qnil, Qnil, Qnil);
|
2017-12-12 06:47:16 -05:00
|
|
|
|
2017-10-26 07:02:13 -04:00
|
|
|
EC_POP_TAG();
|
2017-10-29 10:06:58 -04:00
|
|
|
ec->errinfo = errinfo;
|
2017-11-07 00:22:09 -05:00
|
|
|
rb_ec_raised_set(ec, raised_flag);
|
2006-12-31 10:02:22 -05:00
|
|
|
}
|
|
|
|
|
2018-10-13 05:59:22 -04:00
|
|
|
#define undef_mesg_for(v, k) rb_fstring_lit("undefined"v" method `%1$s' for "k" `%2$s'")
|
2015-10-28 02:24:12 -04:00
|
|
|
#define undef_mesg(v) ( \
|
|
|
|
is_mod ? \
|
|
|
|
undef_mesg_for(v, "module") : \
|
|
|
|
undef_mesg_for(v, "class"))
|
2014-07-26 12:13:21 -04:00
|
|
|
|
|
|
|
void
|
2016-01-02 23:59:54 -05:00
|
|
|
rb_print_undef(VALUE klass, ID id, rb_method_visibility_t visi)
|
2014-07-26 12:13:21 -04:00
|
|
|
{
|
2015-10-28 02:24:12 -04:00
|
|
|
const int is_mod = RB_TYPE_P(klass, T_MODULE);
|
|
|
|
VALUE mesg;
|
|
|
|
switch (visi & METHOD_VISI_MASK) {
|
|
|
|
case METHOD_VISI_UNDEF:
|
|
|
|
case METHOD_VISI_PUBLIC: mesg = undef_mesg(""); break;
|
|
|
|
case METHOD_VISI_PRIVATE: mesg = undef_mesg(" private"); break;
|
|
|
|
case METHOD_VISI_PROTECTED: mesg = undef_mesg(" protected"); break;
|
|
|
|
default: UNREACHABLE;
|
|
|
|
}
|
|
|
|
rb_name_err_raise_str(mesg, klass, ID2SYM(id));
|
2006-12-31 10:02:22 -05:00
|
|
|
}
|
|
|
|
|
2011-07-26 12:05:35 -04:00
|
|
|
void
|
|
|
|
rb_print_undef_str(VALUE klass, VALUE name)
|
|
|
|
{
|
2015-10-28 02:24:12 -04:00
|
|
|
const int is_mod = RB_TYPE_P(klass, T_MODULE);
|
|
|
|
rb_name_err_raise_str(undef_mesg(""), klass, name);
|
2011-07-26 12:05:35 -04:00
|
|
|
}
|
|
|
|
|
2018-10-13 05:59:22 -04:00
|
|
|
#define inaccessible_mesg_for(v, k) rb_fstring_lit("method `%1$s' for "k" `%2$s' is "v)
|
2015-10-28 02:24:12 -04:00
|
|
|
#define inaccessible_mesg(v) ( \
|
|
|
|
is_mod ? \
|
|
|
|
inaccessible_mesg_for(v, "module") : \
|
|
|
|
inaccessible_mesg_for(v, "class"))
|
|
|
|
|
2014-07-26 12:13:21 -04:00
|
|
|
void
|
2015-06-02 21:39:16 -04:00
|
|
|
rb_print_inaccessible(VALUE klass, ID id, rb_method_visibility_t visi)
|
2014-07-26 12:13:21 -04:00
|
|
|
{
|
2015-10-28 02:24:12 -04:00
|
|
|
const int is_mod = RB_TYPE_P(klass, T_MODULE);
|
|
|
|
VALUE mesg;
|
|
|
|
switch (visi & METHOD_VISI_MASK) {
|
|
|
|
case METHOD_VISI_UNDEF:
|
|
|
|
case METHOD_VISI_PUBLIC: mesg = inaccessible_mesg(""); break;
|
|
|
|
case METHOD_VISI_PRIVATE: mesg = inaccessible_mesg(" private"); break;
|
|
|
|
case METHOD_VISI_PROTECTED: mesg = inaccessible_mesg(" protected"); break;
|
|
|
|
default: UNREACHABLE;
|
|
|
|
}
|
|
|
|
rb_name_err_raise_str(mesg, klass, ID2SYM(id));
|
2014-07-26 12:13:21 -04:00
|
|
|
}
|
|
|
|
|
2006-12-31 10:02:22 -05:00
|
|
|
static int
|
|
|
|
sysexit_status(VALUE err)
|
|
|
|
{
|
2015-02-23 02:05:30 -05:00
|
|
|
VALUE st = rb_ivar_get(err, id_status);
|
2006-12-31 10:02:22 -05:00
|
|
|
return NUM2INT(st);
|
|
|
|
}
|
|
|
|
|
2015-07-18 20:25:45 -04:00
|
|
|
#define unknown_longjmp_status(status) \
|
|
|
|
rb_bug("Unknown longjmp status %d", status)
|
|
|
|
|
2006-12-31 10:02:22 -05:00
|
|
|
static int
|
2019-08-12 04:44:30 -04:00
|
|
|
error_handle(rb_execution_context_t *ec, int ex)
|
2006-12-31 10:02:22 -05:00
|
|
|
{
|
|
|
|
int status = EXIT_FAILURE;
|
|
|
|
|
2017-11-07 00:12:39 -05:00
|
|
|
if (rb_ec_set_raised(ec))
|
2006-12-31 10:02:22 -05:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
switch (ex & TAG_MASK) {
|
* call_cfunc.ci, compile.c, compile.h, debug.h, eval.c,
eval_error.h, eval_jump.h, eval_load.c, eval_thread.c, gc.c,
insnhelper.h, insns.def, iseq.c, main.c, numeric.c, parse.y,
range.c, regenc.h, ruby.h, signal.c, thread.c, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, yarvcore.c, yarvcore.h:
fixed indents and non-C90 comments.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11620 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-02 11:26:04 -05:00
|
|
|
case 0:
|
2006-12-31 10:02:22 -05:00
|
|
|
status = EXIT_SUCCESS;
|
|
|
|
break;
|
|
|
|
|
* call_cfunc.ci, compile.c, compile.h, debug.h, eval.c,
eval_error.h, eval_jump.h, eval_load.c, eval_thread.c, gc.c,
insnhelper.h, insns.def, iseq.c, main.c, numeric.c, parse.y,
range.c, regenc.h, ruby.h, signal.c, thread.c, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, yarvcore.c, yarvcore.h:
fixed indents and non-C90 comments.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11620 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-02 11:26:04 -05:00
|
|
|
case TAG_RETURN:
|
2017-12-12 06:47:16 -05:00
|
|
|
error_pos(Qnil);
|
2016-02-24 23:42:16 -05:00
|
|
|
warn_print("unexpected return\n");
|
2006-12-31 10:02:22 -05:00
|
|
|
break;
|
* call_cfunc.ci, compile.c, compile.h, debug.h, eval.c,
eval_error.h, eval_jump.h, eval_load.c, eval_thread.c, gc.c,
insnhelper.h, insns.def, iseq.c, main.c, numeric.c, parse.y,
range.c, regenc.h, ruby.h, signal.c, thread.c, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, yarvcore.c, yarvcore.h:
fixed indents and non-C90 comments.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11620 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-02 11:26:04 -05:00
|
|
|
case TAG_NEXT:
|
2017-12-12 06:47:16 -05:00
|
|
|
error_pos(Qnil);
|
2016-02-24 23:42:16 -05:00
|
|
|
warn_print("unexpected next\n");
|
2006-12-31 10:02:22 -05:00
|
|
|
break;
|
* call_cfunc.ci, compile.c, compile.h, debug.h, eval.c,
eval_error.h, eval_jump.h, eval_load.c, eval_thread.c, gc.c,
insnhelper.h, insns.def, iseq.c, main.c, numeric.c, parse.y,
range.c, regenc.h, ruby.h, signal.c, thread.c, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, yarvcore.c, yarvcore.h:
fixed indents and non-C90 comments.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11620 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-02 11:26:04 -05:00
|
|
|
case TAG_BREAK:
|
2017-12-12 06:47:16 -05:00
|
|
|
error_pos(Qnil);
|
2016-02-24 23:42:16 -05:00
|
|
|
warn_print("unexpected break\n");
|
2006-12-31 10:02:22 -05:00
|
|
|
break;
|
* call_cfunc.ci, compile.c, compile.h, debug.h, eval.c,
eval_error.h, eval_jump.h, eval_load.c, eval_thread.c, gc.c,
insnhelper.h, insns.def, iseq.c, main.c, numeric.c, parse.y,
range.c, regenc.h, ruby.h, signal.c, thread.c, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, yarvcore.c, yarvcore.h:
fixed indents and non-C90 comments.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11620 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-02 11:26:04 -05:00
|
|
|
case TAG_REDO:
|
2017-12-12 06:47:16 -05:00
|
|
|
error_pos(Qnil);
|
2016-02-24 23:42:16 -05:00
|
|
|
warn_print("unexpected redo\n");
|
2006-12-31 10:02:22 -05:00
|
|
|
break;
|
* call_cfunc.ci, compile.c, compile.h, debug.h, eval.c,
eval_error.h, eval_jump.h, eval_load.c, eval_thread.c, gc.c,
insnhelper.h, insns.def, iseq.c, main.c, numeric.c, parse.y,
range.c, regenc.h, ruby.h, signal.c, thread.c, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, yarvcore.c, yarvcore.h:
fixed indents and non-C90 comments.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11620 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-02 11:26:04 -05:00
|
|
|
case TAG_RETRY:
|
2017-12-12 06:47:16 -05:00
|
|
|
error_pos(Qnil);
|
2016-02-24 23:42:16 -05:00
|
|
|
warn_print("retry outside of rescue clause\n");
|
2006-12-31 10:02:22 -05:00
|
|
|
break;
|
* call_cfunc.ci, compile.c, compile.h, debug.h, eval.c,
eval_error.h, eval_jump.h, eval_load.c, eval_thread.c, gc.c,
insnhelper.h, insns.def, iseq.c, main.c, numeric.c, parse.y,
range.c, regenc.h, ruby.h, signal.c, thread.c, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, yarvcore.c, yarvcore.h:
fixed indents and non-C90 comments.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11620 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-02 11:26:04 -05:00
|
|
|
case TAG_THROW:
|
|
|
|
/* TODO: fix me */
|
2017-12-12 06:47:16 -05:00
|
|
|
error_pos(Qnil);
|
2016-02-24 23:42:16 -05:00
|
|
|
warn_print("unexpected throw\n");
|
2006-12-31 10:02:22 -05:00
|
|
|
break;
|
2008-05-27 09:10:46 -04:00
|
|
|
case TAG_RAISE: {
|
2017-10-29 10:06:58 -04:00
|
|
|
VALUE errinfo = ec->errinfo;
|
2007-04-19 13:37:03 -04:00
|
|
|
if (rb_obj_is_kind_of(errinfo, rb_eSystemExit)) {
|
|
|
|
status = sysexit_status(errinfo);
|
|
|
|
}
|
2014-05-18 04:47:41 -04:00
|
|
|
else if (rb_obj_is_instance_of(errinfo, rb_eSignal) &&
|
2015-02-23 02:05:30 -05:00
|
|
|
rb_ivar_get(errinfo, id_signo) != INT2FIX(SIGSEGV)) {
|
2007-04-19 13:37:03 -04:00
|
|
|
/* no message when exiting by signal */
|
2006-12-31 10:02:22 -05:00
|
|
|
}
|
2020-04-14 12:25:04 -04:00
|
|
|
else if (rb_obj_is_kind_of(errinfo, rb_eSystemCallError) &&
|
|
|
|
FIXNUM_P(rb_attr_get(errinfo, id_signo))) {
|
|
|
|
/* no message when exiting by error to be mapped to signal */
|
|
|
|
}
|
2006-12-31 10:02:22 -05:00
|
|
|
else {
|
2017-10-29 10:06:58 -04:00
|
|
|
rb_ec_error_print(ec, errinfo);
|
2006-12-31 10:02:22 -05:00
|
|
|
}
|
|
|
|
break;
|
2007-04-19 13:37:03 -04:00
|
|
|
}
|
2008-05-27 09:10:46 -04:00
|
|
|
case TAG_FATAL:
|
2017-10-29 10:06:58 -04:00
|
|
|
error_print(ec);
|
2008-05-27 09:10:46 -04:00
|
|
|
break;
|
* call_cfunc.ci, compile.c, compile.h, debug.h, eval.c,
eval_error.h, eval_jump.h, eval_load.c, eval_thread.c, gc.c,
insnhelper.h, insns.def, iseq.c, main.c, numeric.c, parse.y,
range.c, regenc.h, ruby.h, signal.c, thread.c, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, yarvcore.c, yarvcore.h:
fixed indents and non-C90 comments.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11620 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-02 11:26:04 -05:00
|
|
|
default:
|
2015-07-18 20:25:45 -04:00
|
|
|
unknown_longjmp_status(ex);
|
2006-12-31 10:02:22 -05:00
|
|
|
break;
|
|
|
|
}
|
2017-11-06 23:01:13 -05:00
|
|
|
rb_ec_reset_raised(ec);
|
2006-12-31 10:02:22 -05:00
|
|
|
return status;
|
|
|
|
}
|