2007-06-25 04:45:48 +04:00
|
|
|
/* -*-c-*- */
|
2006-12-31 18:02:22 +03:00
|
|
|
/*
|
|
|
|
* included by eval.c
|
|
|
|
*/
|
|
|
|
|
2018-01-07 07:57:04 +03: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 21:12:46 +03: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 15:29:06 +03:00
|
|
|
#define warn_print(x) RB_GNUC_EXTENSION_BLOCK( \
|
2016-03-06 11:34:50 +03: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 15:29:06 +03:00
|
|
|
rb_write_error(x) \
|
|
|
|
)
|
2016-03-06 11:34:50 +03:00
|
|
|
#else
|
2006-12-31 18:02:22 +03:00
|
|
|
#define warn_print(x) rb_write_error(x)
|
2016-03-06 11:34:50 +03:00
|
|
|
#endif
|
2017-12-12 14:47:16 +03:00
|
|
|
|
2010-12-12 07:28:29 +03:00
|
|
|
#define warn_print2(x,l) rb_write_error2((x),(l))
|
2017-12-12 14:47:16 +03:00
|
|
|
|
2017-12-18 18:46:56 +03:00
|
|
|
#define write_warn_str(str,x) NIL_P(str) ? rb_write_error_str(x) : (void)rb_str_concat((str), (x))
|
2013-06-24 17:03:35 +04:00
|
|
|
#define warn_print_str(x) rb_write_error_str(x)
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2016-02-25 15:36:24 +03:00
|
|
|
static VALUE error_pos_str(void);
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
static void
|
2017-12-12 14:47:16 +03:00
|
|
|
error_pos(const VALUE str)
|
2016-02-25 15:36:24 +03:00
|
|
|
{
|
2017-12-12 14:47:16 +03:00
|
|
|
VALUE pos = error_pos_str();
|
|
|
|
if (!NIL_P(pos)) {
|
|
|
|
write_warn_str(str, pos);
|
2016-02-25 15:36:24 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
error_pos_str(void)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
2015-10-31 04:02:26 +03:00
|
|
|
int sourceline;
|
|
|
|
VALUE sourcefile = rb_source_location(&sourceline);
|
2007-06-25 00:33:04 +04:00
|
|
|
|
2017-11-16 08:35:58 +03:00
|
|
|
if (!NIL_P(sourcefile)) {
|
2013-05-25 02:03:41 +04:00
|
|
|
ID caller_name;
|
2007-06-25 00:33:04 +04:00
|
|
|
if (sourceline == 0) {
|
2016-02-25 15:36:24 +03:00
|
|
|
return rb_sprintf("%"PRIsVALUE": ", sourcefile);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
2013-05-25 02:03:41 +04:00
|
|
|
else if ((caller_name = rb_frame_callee()) != 0) {
|
2016-02-25 15:36:24 +03:00
|
|
|
return rb_sprintf("%"PRIsVALUE":%d:in `%"PRIsVALUE"': ",
|
|
|
|
sourcefile, sourceline,
|
|
|
|
rb_id2str(caller_name));
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
else {
|
2016-02-25 15:36:24 +03:00
|
|
|
return rb_sprintf("%"PRIsVALUE":%d: ", sourcefile, sourceline);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
}
|
2016-02-25 15:36:24 +03:00
|
|
|
return Qnil;
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
set_backtrace(VALUE info, VALUE bt)
|
|
|
|
{
|
2012-05-24 10:09:23 +04:00
|
|
|
ID set_backtrace = rb_intern("set_backtrace");
|
|
|
|
|
|
|
|
if (rb_backtrace_p(bt)) {
|
2012-05-24 10:36:44 +04:00
|
|
|
if (rb_method_basic_definition_p(CLASS_OF(info), set_backtrace)) {
|
2012-05-24 10:09:23 +04:00
|
|
|
rb_exc_set_backtrace(info, bt);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
bt = rb_backtrace_to_str_ary(bt);
|
|
|
|
}
|
|
|
|
}
|
2016-11-13 08:25:53 +03:00
|
|
|
rb_check_funcall(info, set_backtrace, 1, &bt);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-10-29 17:06:58 +03:00
|
|
|
error_print(rb_execution_context_t *ec)
|
2016-06-06 03:25:38 +03:00
|
|
|
{
|
2017-10-29 17:06:58 +03:00
|
|
|
rb_ec_error_print(ec, ec->errinfo);
|
2016-06-06 03:25:38 +03:00
|
|
|
}
|
|
|
|
|
2019-01-08 12:08:31 +03: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 13:10:18 +03:00
|
|
|
switch (c) {
|
|
|
|
case '\n': case '\t': continue;
|
|
|
|
}
|
2019-01-08 12:08:31 +03: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 11:39:03 +03: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 11:50:25 +03:00
|
|
|
static void
|
2018-01-07 07:16:31 +03:00
|
|
|
print_errinfo(const VALUE eclass, const VALUE errat, const VALUE emesg, const VALUE str, int highlight)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
2017-02-22 11:50:25 +03:00
|
|
|
const char *einfo = "";
|
|
|
|
long elen = 0;
|
2016-02-25 10:22:01 +03:00
|
|
|
VALUE mesg;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2017-02-22 11:50:25 +03:00
|
|
|
if (emesg != Qundef) {
|
|
|
|
if (NIL_P(errat) || RARRAY_LEN(errat) == 0 ||
|
|
|
|
NIL_P(mesg = RARRAY_AREF(errat, 0))) {
|
2017-12-12 14:47:16 +03:00
|
|
|
error_pos(str);
|
2017-02-22 11:50:25 +03:00
|
|
|
}
|
|
|
|
else {
|
2017-12-12 14:47:16 +03:00
|
|
|
write_warn_str(str, mesg);
|
|
|
|
write_warn(str, ": ");
|
2017-02-22 11:50:25 +03:00
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2017-02-22 11:50:25 +03:00
|
|
|
if (!NIL_P(emesg)) {
|
|
|
|
einfo = RSTRING_PTR(emesg);
|
2017-11-29 14:14:23 +03:00
|
|
|
elen = RSTRING_LEN(emesg);
|
2017-02-22 11:50:25 +03:00
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (eclass == rb_eRuntimeError && elen == 0) {
|
2018-01-07 07:16:31 +03:00
|
|
|
if (highlight) write_warn(str, underline);
|
2018-01-07 08:38:37 +03:00
|
|
|
write_warn(str, "unhandled exception");
|
|
|
|
if (highlight) write_warn(str, reset);
|
|
|
|
write_warn2(str, "\n", 1);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
VALUE epath;
|
|
|
|
|
|
|
|
epath = rb_class_name(eclass);
|
|
|
|
if (elen == 0) {
|
2018-01-07 07:16:31 +03:00
|
|
|
if (highlight) write_warn(str, underline);
|
2017-12-12 14:47:16 +03:00
|
|
|
write_warn_str(str, epath);
|
2018-01-07 08:38:37 +03:00
|
|
|
if (highlight) write_warn(str, reset);
|
2017-12-12 14:47:16 +03:00
|
|
|
write_warn(str, "\n");
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
else {
|
2019-07-15 10:51:18 +03:00
|
|
|
/* emesg is a String instance */
|
2016-02-25 15:36:25 +03:00
|
|
|
const char *tail = 0;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2019-07-15 10:51:18 +03:00
|
|
|
if (highlight) write_warn(str, bold);
|
2006-12-31 18:02:22 +03:00
|
|
|
if (RSTRING_PTR(epath)[0] == '#')
|
|
|
|
epath = 0;
|
2007-08-18 11:44:51 +04:00
|
|
|
if ((tail = memchr(einfo, '\n', elen)) != 0) {
|
2019-01-08 12:08:37 +03:00
|
|
|
write_warnq(str, emesg, einfo, tail - einfo);
|
2006-12-31 18:02:22 +03:00
|
|
|
tail++; /* skip newline */
|
2018-01-07 08:38:37 +03:00
|
|
|
}
|
|
|
|
else {
|
2019-01-08 12:08:37 +03:00
|
|
|
write_warnq(str, emesg, einfo, elen);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
if (epath) {
|
2017-12-12 14:47:16 +03:00
|
|
|
write_warn(str, " (");
|
2018-01-07 07:16:31 +03:00
|
|
|
if (highlight) write_warn(str, underline);
|
2017-12-12 14:47:16 +03:00
|
|
|
write_warn_str(str, epath);
|
2018-01-07 08:38:37 +03:00
|
|
|
if (highlight) {
|
|
|
|
write_warn(str, reset);
|
|
|
|
write_warn(str, bold);
|
|
|
|
}
|
|
|
|
write_warn2(str, ")", 1);
|
2018-01-07 07:16:31 +03:00
|
|
|
if (highlight) write_warn(str, reset);
|
2018-01-07 08:38:37 +03:00
|
|
|
write_warn2(str, "\n", 1);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
2018-03-13 06:48:56 +03:00
|
|
|
if (tail && einfo+elen > tail) {
|
|
|
|
if (!highlight) {
|
2019-01-08 12:08:37 +03:00
|
|
|
write_warnq(str, emesg, tail, einfo+elen-tail);
|
2018-03-13 06:48:56 +03: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 12:08:37 +03:00
|
|
|
write_warnq(str, emesg, einfo, tail ? tail-einfo : elen);
|
2018-03-13 06:48:56 +03: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 12:08:37 +03:00
|
|
|
write_warnq(str, emesg, einfo, tail-einfo);
|
2018-03-13 06:48:56 +03:00
|
|
|
elen -= tail - einfo;
|
|
|
|
einfo = tail;
|
|
|
|
}
|
2018-01-07 08:38:37 +03:00
|
|
|
}
|
|
|
|
}
|
2018-03-13 06:40:10 +03:00
|
|
|
else if (!epath) {
|
2018-01-07 08:38:37 +03:00
|
|
|
write_warn2(str, "\n", 1);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-02-22 11:50:25 +03:00
|
|
|
}
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2017-02-22 11:50:25 +03:00
|
|
|
static void
|
2017-12-12 14:47:16 +03:00
|
|
|
print_backtrace(const VALUE eclass, const VALUE errat, const VALUE str, int reverse)
|
2017-02-22 11:50:25 +03:00
|
|
|
{
|
2006-12-31 18:02:22 +03:00
|
|
|
if (!NIL_P(errat)) {
|
|
|
|
long i;
|
|
|
|
long len = RARRAY_LEN(errat);
|
2007-06-20 03:27:47 +04:00
|
|
|
int skip = eclass == rb_eSysStackError;
|
2017-05-19 10:12:45 +03:00
|
|
|
const int threshold = 1000000000;
|
2018-11-15 12:03:03 +03:00
|
|
|
int width = (len <= 1) ? INT_MIN : ((int)log10((double)(len > threshold ?
|
2017-05-19 10:12:45 +03:00
|
|
|
((len - 1) / threshold) :
|
|
|
|
len - 1)) +
|
2017-05-19 10:34:05 +03:00
|
|
|
(len < threshold ? 0 : 9) + 1);
|
2009-02-22 17:23:33 +03:00
|
|
|
|
2006-12-31 18:02:22 +03: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 11:50:25 +03:00
|
|
|
VALUE line = RARRAY_AREF(errat, reverse ? len - i : i);
|
2013-06-11 10:57:04 +04:00
|
|
|
if (RB_TYPE_P(line, T_STRING)) {
|
2017-12-12 14:47:16 +03: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 18:02:22 +03:00
|
|
|
}
|
2007-06-20 03:27:47 +04:00
|
|
|
if (skip && i == TRACE_HEAD && len > TRACE_MAX) {
|
2017-12-12 14:47:16 +03:00
|
|
|
write_warn_str(str, rb_sprintf("\t ... %ld levels...\n",
|
2016-02-25 15:36:24 +03:00
|
|
|
len - TRACE_HEAD - TRACE_TAIL));
|
2006-12-31 18:02:22 +03:00
|
|
|
i = len - TRACE_TAIL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-02-22 11:50:25 +03:00
|
|
|
}
|
|
|
|
|
2018-10-28 00:45:30 +03:00
|
|
|
VALUE rb_get_message(VALUE exc);
|
|
|
|
|
2018-12-22 10:14:14 +03: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-28 00:45:30 +03:00
|
|
|
static void
|
2018-12-22 10:14:14 +03:00
|
|
|
show_cause(VALUE errinfo, VALUE str, VALUE highlight, VALUE reverse, VALUE *shown_causes)
|
2018-10-28 00:45:30 +03:00
|
|
|
{
|
|
|
|
VALUE cause = rb_attr_get(errinfo, id_cause);
|
2018-12-22 10:14:14 +03:00
|
|
|
if (!NIL_P(cause) && rb_obj_is_kind_of(cause, rb_eException) &&
|
|
|
|
!shown_cause_p(cause, shown_causes)) {
|
2018-10-28 00:45:30 +03:00
|
|
|
volatile VALUE eclass = CLASS_OF(cause);
|
|
|
|
VALUE errat = rb_get_backtrace(cause);
|
|
|
|
VALUE emesg = rb_get_message(cause);
|
|
|
|
if (reverse) {
|
2018-12-22 10:14:14 +03:00
|
|
|
show_cause(cause, str, highlight, reverse, shown_causes);
|
2018-10-28 02:13:34 +03:00
|
|
|
print_backtrace(eclass, errat, str, TRUE);
|
2018-10-28 00:45:30 +03:00
|
|
|
print_errinfo(eclass, errat, emesg, str, highlight!=0);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
print_errinfo(eclass, errat, emesg, str, highlight!=0);
|
2018-10-28 02:13:34 +03:00
|
|
|
print_backtrace(eclass, errat, str, FALSE);
|
2018-12-22 10:14:14 +03:00
|
|
|
show_cause(cause, str, highlight, reverse, shown_causes);
|
2018-10-28 00:45:30 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-22 11:50:25 +03:00
|
|
|
void
|
2018-04-11 11:03:43 +03:00
|
|
|
rb_error_write(VALUE errinfo, VALUE emesg, VALUE errat, VALUE str, VALUE highlight, VALUE reverse)
|
2017-02-22 11:50:25 +03:00
|
|
|
{
|
2018-04-11 11:03:43 +03:00
|
|
|
volatile VALUE eclass;
|
2018-12-22 10:14:14 +03:00
|
|
|
VALUE shown_causes = 0;
|
2017-02-22 11:50:25 +03:00
|
|
|
|
|
|
|
if (NIL_P(errinfo))
|
|
|
|
return;
|
|
|
|
|
2017-12-12 14:47:16 +03:00
|
|
|
if (errat == Qundef) {
|
2017-02-22 11:50:25 +03:00
|
|
|
errat = Qnil;
|
|
|
|
}
|
2018-04-11 11:03:43 +03:00
|
|
|
eclass = CLASS_OF(errinfo);
|
2018-02-23 11:39:03 +03: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 10:14:14 +03:00
|
|
|
show_cause(errinfo, str, highlight, reverse, &shown_causes);
|
2017-12-12 14:47:16 +03:00
|
|
|
print_backtrace(eclass, errat, str, TRUE);
|
2018-02-23 11:39:03 +03:00
|
|
|
print_errinfo(eclass, errat, emesg, str, highlight!=0);
|
2017-02-22 11:50:25 +03:00
|
|
|
}
|
|
|
|
else {
|
2018-02-23 11:39:03 +03:00
|
|
|
print_errinfo(eclass, errat, emesg, str, highlight!=0);
|
2017-12-12 14:47:16 +03:00
|
|
|
print_backtrace(eclass, errat, str, FALSE);
|
2018-12-22 10:14:14 +03:00
|
|
|
show_cause(errinfo, str, highlight, reverse, &shown_causes);
|
2017-02-22 11:50:25 +03:00
|
|
|
}
|
2017-12-12 14:47:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
rb_ec_error_print(rb_execution_context_t * volatile ec, volatile VALUE errinfo)
|
|
|
|
{
|
2018-10-19 23:56:10 +03:00
|
|
|
volatile uint8_t raised_flag = ec->raised_flag;
|
2018-01-02 09:42:03 +03:00
|
|
|
volatile VALUE errat = Qundef;
|
2018-04-11 11:03:43 +03:00
|
|
|
volatile VALUE emesg = Qundef;
|
2017-12-12 14:47:16 +03: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 11:03:43 +03:00
|
|
|
if (emesg == Qundef) {
|
|
|
|
emesg = Qnil;
|
|
|
|
emesg = rb_get_message(errinfo);
|
|
|
|
}
|
2017-12-12 14:47:16 +03:00
|
|
|
|
2018-04-11 11:03:43 +03:00
|
|
|
rb_error_write(errinfo, emesg, errat, Qnil, Qnil, Qnil);
|
2017-12-12 14:47:16 +03:00
|
|
|
|
2017-10-26 14:02:13 +03:00
|
|
|
EC_POP_TAG();
|
2017-10-29 17:06:58 +03:00
|
|
|
ec->errinfo = errinfo;
|
2017-11-07 08:22:09 +03:00
|
|
|
rb_ec_raised_set(ec, raised_flag);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
2018-10-13 12:59:22 +03:00
|
|
|
#define undef_mesg_for(v, k) rb_fstring_lit("undefined"v" method `%1$s' for "k" `%2$s'")
|
2015-10-28 09:24:12 +03:00
|
|
|
#define undef_mesg(v) ( \
|
|
|
|
is_mod ? \
|
|
|
|
undef_mesg_for(v, "module") : \
|
|
|
|
undef_mesg_for(v, "class"))
|
2014-07-26 20:13:21 +04:00
|
|
|
|
|
|
|
void
|
2016-01-03 07:59:54 +03:00
|
|
|
rb_print_undef(VALUE klass, ID id, rb_method_visibility_t visi)
|
2014-07-26 20:13:21 +04:00
|
|
|
{
|
2015-10-28 09:24:12 +03: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 18:02:22 +03:00
|
|
|
}
|
|
|
|
|
2011-07-26 20:05:35 +04:00
|
|
|
void
|
|
|
|
rb_print_undef_str(VALUE klass, VALUE name)
|
|
|
|
{
|
2015-10-28 09:24:12 +03:00
|
|
|
const int is_mod = RB_TYPE_P(klass, T_MODULE);
|
|
|
|
rb_name_err_raise_str(undef_mesg(""), klass, name);
|
2011-07-26 20:05:35 +04:00
|
|
|
}
|
|
|
|
|
2018-10-13 12:59:22 +03:00
|
|
|
#define inaccessible_mesg_for(v, k) rb_fstring_lit("method `%1$s' for "k" `%2$s' is "v)
|
2015-10-28 09:24:12 +03:00
|
|
|
#define inaccessible_mesg(v) ( \
|
|
|
|
is_mod ? \
|
|
|
|
inaccessible_mesg_for(v, "module") : \
|
|
|
|
inaccessible_mesg_for(v, "class"))
|
|
|
|
|
2014-07-26 20:13:21 +04:00
|
|
|
void
|
2015-06-03 04:39:16 +03:00
|
|
|
rb_print_inaccessible(VALUE klass, ID id, rb_method_visibility_t visi)
|
2014-07-26 20:13:21 +04:00
|
|
|
{
|
2015-10-28 09:24:12 +03: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 20:13:21 +04:00
|
|
|
}
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
static int
|
|
|
|
sysexit_status(VALUE err)
|
|
|
|
{
|
2015-02-23 10:05:30 +03:00
|
|
|
VALUE st = rb_ivar_get(err, id_status);
|
2006-12-31 18:02:22 +03:00
|
|
|
return NUM2INT(st);
|
|
|
|
}
|
|
|
|
|
2015-07-19 03:25:45 +03:00
|
|
|
#define unknown_longjmp_status(status) \
|
|
|
|
rb_bug("Unknown longjmp status %d", status)
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
static int
|
2019-08-12 11:44:30 +03:00
|
|
|
error_handle(rb_execution_context_t *ec, int ex)
|
2006-12-31 18:02:22 +03:00
|
|
|
{
|
|
|
|
int status = EXIT_FAILURE;
|
|
|
|
|
2017-11-07 08:12:39 +03:00
|
|
|
if (rb_ec_set_raised(ec))
|
2006-12-31 18:02:22 +03: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 19:26:04 +03:00
|
|
|
case 0:
|
2006-12-31 18:02:22 +03: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 19:26:04 +03:00
|
|
|
case TAG_RETURN:
|
2017-12-12 14:47:16 +03:00
|
|
|
error_pos(Qnil);
|
2016-02-25 07:42:16 +03:00
|
|
|
warn_print("unexpected return\n");
|
2006-12-31 18:02:22 +03: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 19:26:04 +03:00
|
|
|
case TAG_NEXT:
|
2017-12-12 14:47:16 +03:00
|
|
|
error_pos(Qnil);
|
2016-02-25 07:42:16 +03:00
|
|
|
warn_print("unexpected next\n");
|
2006-12-31 18:02:22 +03: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 19:26:04 +03:00
|
|
|
case TAG_BREAK:
|
2017-12-12 14:47:16 +03:00
|
|
|
error_pos(Qnil);
|
2016-02-25 07:42:16 +03:00
|
|
|
warn_print("unexpected break\n");
|
2006-12-31 18:02:22 +03: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 19:26:04 +03:00
|
|
|
case TAG_REDO:
|
2017-12-12 14:47:16 +03:00
|
|
|
error_pos(Qnil);
|
2016-02-25 07:42:16 +03:00
|
|
|
warn_print("unexpected redo\n");
|
2006-12-31 18:02:22 +03: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 19:26:04 +03:00
|
|
|
case TAG_RETRY:
|
2017-12-12 14:47:16 +03:00
|
|
|
error_pos(Qnil);
|
2016-02-25 07:42:16 +03:00
|
|
|
warn_print("retry outside of rescue clause\n");
|
2006-12-31 18:02:22 +03: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 19:26:04 +03:00
|
|
|
case TAG_THROW:
|
|
|
|
/* TODO: fix me */
|
2017-12-12 14:47:16 +03:00
|
|
|
error_pos(Qnil);
|
2016-02-25 07:42:16 +03:00
|
|
|
warn_print("unexpected throw\n");
|
2006-12-31 18:02:22 +03:00
|
|
|
break;
|
2008-05-27 17:10:46 +04:00
|
|
|
case TAG_RAISE: {
|
2017-10-29 17:06:58 +03:00
|
|
|
VALUE errinfo = ec->errinfo;
|
2007-04-19 21:37:03 +04:00
|
|
|
if (rb_obj_is_kind_of(errinfo, rb_eSystemExit)) {
|
|
|
|
status = sysexit_status(errinfo);
|
|
|
|
}
|
2014-05-18 12:47:41 +04:00
|
|
|
else if (rb_obj_is_instance_of(errinfo, rb_eSignal) &&
|
2015-02-23 10:05:30 +03:00
|
|
|
rb_ivar_get(errinfo, id_signo) != INT2FIX(SIGSEGV)) {
|
2007-04-19 21:37:03 +04:00
|
|
|
/* no message when exiting by signal */
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
else {
|
2017-10-29 17:06:58 +03:00
|
|
|
rb_ec_error_print(ec, errinfo);
|
2006-12-31 18:02:22 +03:00
|
|
|
}
|
|
|
|
break;
|
2007-04-19 21:37:03 +04:00
|
|
|
}
|
2008-05-27 17:10:46 +04:00
|
|
|
case TAG_FATAL:
|
2017-10-29 17:06:58 +03:00
|
|
|
error_print(ec);
|
2008-05-27 17: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 19:26:04 +03:00
|
|
|
default:
|
2015-07-19 03:25:45 +03:00
|
|
|
unknown_longjmp_status(ex);
|
2006-12-31 18:02:22 +03:00
|
|
|
break;
|
|
|
|
}
|
2017-11-07 07:01:13 +03:00
|
|
|
rb_ec_reset_raised(ec);
|
2006-12-31 18:02:22 +03:00
|
|
|
return status;
|
|
|
|
}
|