don't overwrite backtrace info.
MODIFY
src/backtrace.c
src/backtrace.c
@@ -215,11 +215,14 @@ packed_backtrace(mrb_state *mrb)
void
mrb_keep_backtrace(mrb_state *mrb, mrb_value exc)
{
+ mrb_sym sym = mrb_intern_lit(mrb, "backtrace");
mrb_value backtrace;
- int ai = mrb_gc_arena_save(mrb);
+ int ai;
+ if (mrb_iv_defined(mrb, exc, sym)) return;
+ ai = mrb_gc_arena_save(mrb);
backtrace = packed_backtrace(mrb);
- mrb_iv_set(mrb, exc, mrb_intern_lit(mrb, "backtrace"), backtrace);
+ mrb_iv_set(mrb, exc, sym, backtrace);
mrb_gc_arena_restore(mrb, ai);
}

MODIFY
src/error.c
src/error.c
@@ -200,6 +200,7 @@ exc_debug_info(mrb_state *mrb, struct RObject *exc)
mrb_callinfo *ci = mrb->c->ci;
mrb_code *pc = ci->pc;
+ if (mrb_obj_iv_defined(mrb, exc, mrb_intern_lit(mrb, "file"))) return;
while (ci >= mrb->c->cibase) {
mrb_code *err = ci->err;

don't overwrite backtrace info.