[Bug #19016] Handle syntax error in main script like other errors
So that `SyntaxError#detailed_message` will be used also in the case exiting by such syntax error.
This commit is contained in:
parent
12b7b85227
commit
701dfe4eb7
Notes:
git
2022-11-20 13:44:17 +00:00
3
eval.c
3
eval.c
@ -121,6 +121,7 @@ ruby_options(int argc, char **argv)
|
|||||||
else {
|
else {
|
||||||
rb_ec_clear_current_thread_trace_func(ec);
|
rb_ec_clear_current_thread_trace_func(ec);
|
||||||
state = error_handle(ec, state);
|
state = error_handle(ec, state);
|
||||||
|
ec->errinfo = Qnil; /* just been handled */
|
||||||
iseq = (void *)INT2FIX(state);
|
iseq = (void *)INT2FIX(state);
|
||||||
}
|
}
|
||||||
EC_POP_TAG();
|
EC_POP_TAG();
|
||||||
@ -317,7 +318,7 @@ ruby_run_node(void *n)
|
|||||||
rb_execution_context_t *ec = GET_EC();
|
rb_execution_context_t *ec = GET_EC();
|
||||||
int status;
|
int status;
|
||||||
if (!ruby_executable_node(n, &status)) {
|
if (!ruby_executable_node(n, &status)) {
|
||||||
rb_ec_cleanup(ec, 0);
|
rb_ec_cleanup(ec, (NIL_P(ec->errinfo) ? TAG_NONE : TAG_RAISE));
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
ruby_init_stack((void *)&status);
|
ruby_init_stack((void *)&status);
|
||||||
|
@ -1457,4 +1457,21 @@ $stderr = $stdout; raise "\x82\xa0"') do |outs, errs, status|
|
|||||||
assert_match("BOO!", e.full_message.lines.first)
|
assert_match("BOO!", e.full_message.lines.first)
|
||||||
assert_equal({ highlight: Exception.to_tty? }, opt_)
|
assert_equal({ highlight: Exception.to_tty? }, opt_)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_syntax_error_detailed_message
|
||||||
|
Tempfile.create(%w[detail .rb]) do |lib|
|
||||||
|
lib.print "#{<<~"begin;"}\n#{<<~'end;'}"
|
||||||
|
begin;
|
||||||
|
class SyntaxError
|
||||||
|
def detailed_message(**)
|
||||||
|
Thread.start {}.join
|
||||||
|
"#{super}\n""<#{File.basename(__FILE__)}>"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end;
|
||||||
|
lib.close
|
||||||
|
pattern = /^<#{Regexp.quote(File.basename(lib.path))}>/
|
||||||
|
assert_in_out_err(%W[-r#{lib.path} -], "1+", [], pattern)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user