`RubyVM::InstructionSequence.compile` should return the error message within the raised error
RubyVM::InstructionSequence.compile raises a syntax error, it outputs the syntax error message to
$stderr, and then raises a
SyntaxError anyway, whose message is simply:
I don't think this is useful. For example, if I want to analyze within Ruby code whether a certain string is syntactically correct Ruby code, I would have to reasign
$stderr to something such as
RubyVM::InstructionSequence.compile, rescue the syntax error, (but instead of reading the error message from the error), read the error message by doing
$stderr.string. This is cumbersome.
On the other hand, there is
eval, which also can raise a SyntaxError. But with
eval, the error message comes out with the raised error, and is useful. I don't see any reason why
RubyVM::InstructionSequence.compile should behave differently from
eval with respect to returning the error message.
RubyVM::InstructionSequence.compile to return the error message as the message on the raised error rather than directly printing it to
Updated by nobu (Nobuyoshi Nakada) over 5 years ago
- Status changed from Open to Closed
Applied in changeset r54189.
SyntaxError message at iseq compile
- iseq.c (rb_iseq_compile_with_option): make the parser in mild error.
- load.c (rb_load_internal0): ditto.
- parse.y (yycompile0): return the error message within the error to be raised. [Feature #11951]
- parse.y (parser_compile_error): accumulate error messages in the error_buffer.