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)) ? \
|
2022-07-21 12:23:58 -04:00
|
|
|
rb_write_error2((x), (long)strlen(x)) : \
|
|
|
|
rb_write_error(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
|
|
|
)
|
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)) {
|
2022-07-21 12:23:58 -04:00
|
|
|
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)) {
|
2022-07-21 12:23:58 -04:00
|
|
|
ID caller_name;
|
|
|
|
if (sourceline == 0) {
|
|
|
|
return rb_sprintf("%"PRIsVALUE": ", sourcefile);
|
|
|
|
}
|
|
|
|
else if ((caller_name = rb_frame_callee()) != 0) {
|
|
|
|
return rb_sprintf("%"PRIsVALUE":%d:in `%"PRIsVALUE"': ",
|
|
|
|
sourcefile, sourceline,
|
|
|
|
rb_id2str(caller_name));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
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)) {
|
2022-07-21 12:23:58 -04:00
|
|
|
if (rb_method_basic_definition_p(CLASS_OF(info), set_backtrace)) {
|
|
|
|
rb_exc_set_backtrace(info, bt);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
bt = rb_backtrace_to_str_ary(bt);
|
|
|
|
}
|
2012-05-24 02:09:23 -04:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
long elen = 0;
|
2016-02-25 02:22:01 -05:00
|
|
|
VALUE mesg;
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2022-02-01 03:03:58 -05:00
|
|
|
if (NIL_P(errat) || RARRAY_LEN(errat) == 0 ||
|
|
|
|
NIL_P(mesg = RARRAY_AREF(errat, 0))) {
|
|
|
|
error_pos(str);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
write_warn_str(str, mesg);
|
|
|
|
write_warn(str, ": ");
|
|
|
|
}
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2022-02-01 03:03:58 -05:00
|
|
|
if (!NIL_P(emesg)) {
|
|
|
|
elen = RSTRING_LEN(emesg);
|
2006-12-31 10:02:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (eclass == rb_eRuntimeError && elen == 0) {
|
2022-07-21 12:23:58 -04:00
|
|
|
if (highlight) write_warn(str, underline);
|
|
|
|
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 {
|
2022-07-21 12:23:58 -04:00
|
|
|
VALUE epath;
|
|
|
|
|
|
|
|
epath = rb_class_name(eclass);
|
|
|
|
if (elen == 0) {
|
|
|
|
if (highlight) write_warn(str, underline);
|
|
|
|
write_warn_str(str, epath);
|
|
|
|
if (highlight) write_warn(str, reset);
|
|
|
|
write_warn(str, "\n");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
write_warn_str(str, emesg);
|
|
|
|
write_warn(str, "\n");
|
2022-02-01 03:03:58 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
|
|
|
rb_decorate_message(const VALUE eclass, const VALUE emesg, int highlight)
|
|
|
|
{
|
|
|
|
const char *einfo = "";
|
|
|
|
long elen = 0;
|
|
|
|
|
|
|
|
VALUE str = rb_str_new2("");
|
|
|
|
|
|
|
|
if (!NIL_P(emesg)) {
|
|
|
|
einfo = RSTRING_PTR(emesg);
|
|
|
|
elen = RSTRING_LEN(emesg);
|
|
|
|
}
|
|
|
|
if (eclass == rb_eRuntimeError && elen == 0) {
|
2022-07-21 12:23:58 -04:00
|
|
|
if (highlight) write_warn(str, underline);
|
|
|
|
write_warn(str, "unhandled exception");
|
|
|
|
if (highlight) write_warn(str, reset);
|
2022-02-01 03:03:58 -05:00
|
|
|
}
|
|
|
|
else {
|
2022-07-21 12:23:58 -04:00
|
|
|
VALUE epath;
|
|
|
|
|
|
|
|
epath = rb_class_name(eclass);
|
|
|
|
if (elen == 0) {
|
|
|
|
if (highlight) write_warn(str, underline);
|
|
|
|
write_warn_str(str, epath);
|
|
|
|
if (highlight) write_warn(str, reset);
|
|
|
|
}
|
|
|
|
else {
|
2019-07-15 03:51:18 -04:00
|
|
|
/* emesg is a String instance */
|
2022-07-21 12:23:58 -04: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);
|
2022-07-21 12:23:58 -04:00
|
|
|
if (RSTRING_PTR(epath)[0] == '#')
|
|
|
|
epath = 0;
|
|
|
|
if ((tail = memchr(einfo, '\n', elen)) != 0) {
|
2022-02-01 02:32:38 -05:00
|
|
|
write_warn2(str, einfo, tail - einfo);
|
2022-07-21 12:23:58 -04:00
|
|
|
tail++; /* skip newline */
|
|
|
|
}
|
|
|
|
else {
|
2022-02-01 02:32:38 -05:00
|
|
|
write_warn_str(str, emesg);
|
2022-07-21 12:23:58 -04:00
|
|
|
}
|
|
|
|
if (epath) {
|
|
|
|
write_warn(str, " (");
|
|
|
|
if (highlight) write_warn(str, underline);
|
2017-12-12 06:47:16 -05:00
|
|
|
write_warn_str(str, epath);
|
2022-07-21 12:23:58 -04:00
|
|
|
if (highlight) {
|
|
|
|
write_warn(str, reset);
|
|
|
|
write_warn(str, bold);
|
|
|
|
}
|
|
|
|
write_warn2(str, ")", 1);
|
|
|
|
if (highlight) write_warn(str, reset);
|
|
|
|
}
|
|
|
|
if (tail && einfo+elen > tail) {
|
|
|
|
if (!highlight) {
|
2022-02-01 03:03:58 -05:00
|
|
|
write_warn2(str, "\n", 1);
|
2022-02-01 02:32:38 -05:00
|
|
|
write_warn2(str, tail, einfo+elen-tail);
|
2022-07-21 12:23:58 -04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
elen -= tail - einfo;
|
|
|
|
einfo = tail;
|
2022-02-01 01:58:39 -05:00
|
|
|
write_warn2(str, "\n", 1);
|
2022-07-21 12:23:58 -04:00
|
|
|
while (elen > 0) {
|
|
|
|
tail = memchr(einfo, '\n', elen);
|
|
|
|
if (!tail || tail > einfo) {
|
|
|
|
write_warn(str, bold);
|
2022-02-01 02:32:38 -05:00
|
|
|
write_warn2(str, einfo, tail ? tail-einfo : elen);
|
2022-07-21 12:23:58 -04:00
|
|
|
write_warn(str, reset);
|
|
|
|
if (!tail) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elen -= tail - einfo;
|
|
|
|
einfo = tail;
|
|
|
|
do ++tail; while (tail < einfo+elen && *tail == '\n');
|
2022-02-01 02:32:38 -05:00
|
|
|
write_warn2(str, einfo, tail-einfo);
|
2022-07-21 12:23:58 -04:00
|
|
|
elen -= tail - einfo;
|
|
|
|
einfo = tail;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-12-31 10:02:22 -05:00
|
|
|
}
|
2022-02-01 03:03:58 -05:00
|
|
|
|
|
|
|
return 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
|
|
|
static void
|
2020-12-27 06:50:15 -05:00
|
|
|
print_backtrace(const VALUE eclass, const VALUE errat, const VALUE str, int reverse, long backtrace_limit)
|
2017-02-22 03:50:25 -05:00
|
|
|
{
|
2006-12-31 10:02:22 -05:00
|
|
|
if (!NIL_P(errat)) {
|
2022-07-21 12:23:58 -04:00
|
|
|
long i;
|
|
|
|
long len = RARRAY_LEN(errat);
|
|
|
|
const int threshold = 1000000000;
|
2018-11-15 04:03:03 -05:00
|
|
|
int width = (len <= 1) ? INT_MIN : ((int)log10((double)(len > threshold ?
|
2022-07-21 12:23:58 -04:00
|
|
|
((len - 1) / threshold) :
|
|
|
|
len - 1)) +
|
|
|
|
(len < threshold ? 0 : 9) + 1);
|
2009-02-22 09:23:33 -05:00
|
|
|
|
2020-05-14 12:22:56 -04:00
|
|
|
long skip_start = -1, skip_len = 0;
|
|
|
|
|
|
|
|
// skip for stackoverflow
|
|
|
|
if (eclass == rb_eSysStackError) {
|
|
|
|
long trace_head = 9;
|
|
|
|
long trace_tail = 4;
|
|
|
|
long trace_max = trace_head + trace_tail + 5;
|
|
|
|
if (len > trace_max) {
|
|
|
|
skip_start = trace_head;
|
|
|
|
skip_len = len - trace_max + 5;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// skip for explicit limit
|
2020-12-27 06:50:15 -05:00
|
|
|
if (backtrace_limit >= 0 && len > backtrace_limit + 2) {
|
|
|
|
skip_start = backtrace_limit + 1;
|
2020-12-20 21:33:22 -05:00
|
|
|
skip_len = len - skip_start;
|
2020-05-14 12:22:56 -04:00
|
|
|
}
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2022-07-21 12:23:58 -04:00
|
|
|
for (i = 1; i < len; i++) {
|
|
|
|
if (i == skip_start) {
|
|
|
|
write_warn_str(str, rb_sprintf("\t ... %ld levels...\n", skip_len));
|
|
|
|
i += skip_len;
|
2020-05-14 12:22:56 -04:00
|
|
|
if (i >= len) break;
|
2022-07-21 12:23:58 -04:00
|
|
|
}
|
|
|
|
VALUE line = RARRAY_AREF(errat, reverse ? len - i : i);
|
|
|
|
if (RB_TYPE_P(line, T_STRING)) {
|
|
|
|
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
|
|
|
}
|
2017-02-22 03:50:25 -05:00
|
|
|
}
|
|
|
|
|
2022-02-01 03:59:31 -05:00
|
|
|
VALUE rb_get_detailed_message(VALUE exc, VALUE opt);
|
2018-10-27 17:45:30 -04:00
|
|
|
|
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
|
2022-02-01 03:59:31 -05:00
|
|
|
show_cause(VALUE errinfo, VALUE str, VALUE opt, VALUE highlight, VALUE reverse, long backtrace_limit, 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);
|
2022-02-01 03:59:31 -05:00
|
|
|
VALUE emesg = rb_get_detailed_message(cause, opt);
|
2018-10-27 17:45:30 -04:00
|
|
|
if (reverse) {
|
2022-02-01 03:59:31 -05:00
|
|
|
show_cause(cause, str, opt, highlight, reverse, backtrace_limit, shown_causes);
|
2020-12-27 06:50:15 -05:00
|
|
|
print_backtrace(eclass, errat, str, TRUE, backtrace_limit);
|
2022-02-01 01:58:39 -05:00
|
|
|
print_errinfo(eclass, errat, emesg, str, RTEST(highlight));
|
2018-10-27 17:45:30 -04:00
|
|
|
}
|
|
|
|
else {
|
2022-02-01 01:58:39 -05:00
|
|
|
print_errinfo(eclass, errat, emesg, str, RTEST(highlight));
|
2020-12-27 06:50:15 -05:00
|
|
|
print_backtrace(eclass, errat, str, FALSE, backtrace_limit);
|
2022-02-01 03:59:31 -05:00
|
|
|
show_cause(cause, str, opt, highlight, reverse, backtrace_limit, shown_causes);
|
2018-10-27 17:45:30 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-22 03:50:25 -05:00
|
|
|
void
|
2022-02-01 03:59:31 -05:00
|
|
|
rb_error_write(VALUE errinfo, VALUE emesg, VALUE errat, VALUE str, VALUE opt, 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;
|
2020-12-27 06:50:15 -05:00
|
|
|
long backtrace_limit = rb_backtrace_length_limit;
|
2017-02-22 03:50:25 -05:00
|
|
|
|
|
|
|
if (NIL_P(errinfo))
|
2022-07-21 12:23:58 -04:00
|
|
|
return;
|
2017-02-22 03:50:25 -05:00
|
|
|
|
2017-12-12 06:47:16 -05:00
|
|
|
if (errat == Qundef) {
|
2022-07-21 12:23:58 -04:00
|
|
|
errat = Qnil;
|
2017-02-22 03:50:25 -05:00
|
|
|
}
|
2018-04-11 04:03:43 -04:00
|
|
|
eclass = CLASS_OF(errinfo);
|
2018-02-23 03:39:03 -05:00
|
|
|
if (reverse) {
|
2022-07-21 12:23:58 -04:00
|
|
|
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 (RTEST(highlight)) {
|
2018-02-23 03:39:03 -05:00
|
|
|
#define APPEND(s, l) (memcpy(p, s, l), p += (l))
|
2022-07-21 12:23:58 -04:00
|
|
|
APPEND(bold, sizeof(bold)-1);
|
|
|
|
APPEND(traceback, bold_part);
|
|
|
|
APPEND(reset, sizeof(reset)-1);
|
|
|
|
APPEND(traceback + bold_part, sizeof(traceback)-bold_part-1);
|
2018-02-23 03:39:03 -05:00
|
|
|
#undef APPEND
|
2022-07-21 12:23:58 -04:00
|
|
|
len = p - (msg = buff);
|
|
|
|
}
|
|
|
|
write_warn2(str, msg, len);
|
2022-02-01 03:59:31 -05:00
|
|
|
show_cause(errinfo, str, opt, highlight, reverse, backtrace_limit, &shown_causes);
|
2022-07-21 12:23:58 -04:00
|
|
|
print_backtrace(eclass, errat, str, TRUE, backtrace_limit);
|
|
|
|
print_errinfo(eclass, errat, emesg, str, RTEST(highlight));
|
2017-02-22 03:50:25 -05:00
|
|
|
}
|
|
|
|
else {
|
2022-07-21 12:23:58 -04:00
|
|
|
print_errinfo(eclass, errat, emesg, str, RTEST(highlight));
|
|
|
|
print_backtrace(eclass, errat, str, FALSE, backtrace_limit);
|
2022-02-01 03:59:31 -05:00
|
|
|
show_cause(errinfo, str, opt, highlight, reverse, backtrace_limit, &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;
|
2020-07-15 05:46:07 -04:00
|
|
|
volatile bool written = false;
|
2017-12-12 06:47:16 -05:00
|
|
|
|
2022-02-01 03:59:31 -05:00
|
|
|
VALUE opt = rb_hash_new();
|
|
|
|
VALUE highlight = rb_stderr_tty_p() ? Qtrue : Qfalse;
|
|
|
|
rb_hash_aset(opt, ID2SYM(rb_intern_const("highlight")), highlight);
|
|
|
|
|
2017-12-12 06:47:16 -05:00
|
|
|
if (NIL_P(errinfo))
|
2022-07-21 12:23:58 -04:00
|
|
|
return;
|
2017-12-12 06:47:16 -05:00
|
|
|
rb_ec_raised_clear(ec);
|
|
|
|
|
|
|
|
EC_PUSH_TAG(ec);
|
|
|
|
if (EC_EXEC_TAG() == TAG_NONE) {
|
2022-07-21 12:23:58 -04:00
|
|
|
errat = rb_get_backtrace(errinfo);
|
2017-12-12 06:47:16 -05:00
|
|
|
}
|
2018-04-11 04:03:43 -04:00
|
|
|
if (emesg == Qundef) {
|
2022-07-21 12:23:58 -04:00
|
|
|
emesg = Qnil;
|
|
|
|
emesg = rb_get_detailed_message(errinfo, opt);
|
2018-04-11 04:03:43 -04:00
|
|
|
}
|
2017-12-12 06:47:16 -05:00
|
|
|
|
2020-07-15 05:46:07 -04:00
|
|
|
if (!written) {
|
|
|
|
written = true;
|
2022-02-01 03:59:31 -05:00
|
|
|
rb_error_write(errinfo, emesg, errat, Qnil, opt, highlight, Qfalse);
|
2020-07-15 05:46:07 -04:00
|
|
|
}
|
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) ( \
|
2022-07-21 12:23:58 -04:00
|
|
|
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) ( \
|
2022-07-21 12:23:58 -04:00
|
|
|
is_mod ? \
|
|
|
|
inaccessible_mesg_for(v, "module") : \
|
|
|
|
inaccessible_mesg_for(v, "class"))
|
2015-10-28 02:24:12 -04:00
|
|
|
|
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;
|
2021-05-03 09:38:51 -04:00
|
|
|
case METHOD_VISI_PRIVATE: mesg = inaccessible_mesg("private"); break;
|
|
|
|
case METHOD_VISI_PROTECTED: mesg = inaccessible_mesg("protected"); break;
|
2015-10-28 02:24:12 -04:00
|
|
|
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))
|
2022-07-21 12:23:58 -04:00
|
|
|
return EXIT_FAILURE;
|
2006-12-31 10:02:22 -05:00
|
|
|
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:
|
2022-07-21 12:23:58 -04:00
|
|
|
status = EXIT_SUCCESS;
|
|
|
|
break;
|
2006-12-31 10:02:22 -05:00
|
|
|
|
* 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:
|
2022-07-21 12:23:58 -04:00
|
|
|
error_pos(Qnil);
|
|
|
|
warn_print("unexpected return\n");
|
|
|
|
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:
|
2022-07-21 12:23:58 -04:00
|
|
|
error_pos(Qnil);
|
|
|
|
warn_print("unexpected next\n");
|
|
|
|
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:
|
2022-07-21 12:23:58 -04:00
|
|
|
error_pos(Qnil);
|
|
|
|
warn_print("unexpected break\n");
|
|
|
|
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:
|
2022-07-21 12:23:58 -04:00
|
|
|
error_pos(Qnil);
|
|
|
|
warn_print("unexpected redo\n");
|
|
|
|
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:
|
2022-07-21 12:23:58 -04:00
|
|
|
error_pos(Qnil);
|
|
|
|
warn_print("retry outside of rescue clause\n");
|
|
|
|
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:
|
2022-07-21 12:23:58 -04:00
|
|
|
/* TODO: fix me */
|
|
|
|
error_pos(Qnil);
|
|
|
|
warn_print("unexpected throw\n");
|
|
|
|
break;
|
2008-05-27 09:10:46 -04:00
|
|
|
case TAG_RAISE: {
|
2022-07-21 12:23:58 -04:00
|
|
|
VALUE errinfo = ec->errinfo;
|
|
|
|
if (rb_obj_is_kind_of(errinfo, rb_eSystemExit)) {
|
|
|
|
status = sysexit_status(errinfo);
|
|
|
|
}
|
|
|
|
else if (rb_obj_is_instance_of(errinfo, rb_eSignal) &&
|
|
|
|
rb_ivar_get(errinfo, id_signo) != INT2FIX(SIGSEGV)) {
|
|
|
|
/* no message when exiting by signal */
|
|
|
|
}
|
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))) {
|
2022-07-21 12:23:58 -04:00
|
|
|
/* no message when exiting by error to be mapped to signal */
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rb_ec_error_print(ec, errinfo);
|
2020-04-14 12:25:04 -04:00
|
|
|
}
|
2022-07-21 12:23:58 -04:00
|
|
|
break;
|
2007-04-19 13:37:03 -04:00
|
|
|
}
|
2008-05-27 09:10:46 -04:00
|
|
|
case TAG_FATAL:
|
2022-07-21 12:23:58 -04:00
|
|
|
error_print(ec);
|
|
|
|
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:
|
2022-07-21 12:23:58 -04:00
|
|
|
unknown_longjmp_status(ex);
|
|
|
|
break;
|
2006-12-31 10:02:22 -05:00
|
|
|
}
|
2017-11-06 23:01:13 -05:00
|
|
|
rb_ec_reset_raised(ec);
|
2006-12-31 10:02:22 -05:00
|
|
|
return status;
|
|
|
|
}
|