Project

General

Profile

Feature #11951

`RubyVM::InstructionSequence.compile` should return the error message within the raised error

Added by sawa (Tsuyoshi Sawada) over 3 years ago. Updated about 3 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:72711]

Description

When 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: "compile error".

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 StringIO.new, run 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.

I request RubyVM::InstructionSequence.compile to return the error message as the message on the raised error rather than directly printing it to $stderr.


Related issues

Related to Ruby trunk - Feature #11868: Proposal for RubyVM::InstructionSequence.compile to return an object containing the syntax error information currently written to STDERROpenActions

Associated revisions

Revision bc343b85
Added by nobu (Nobuyoshi Nakada) about 3 years ago

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.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54189 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 54189
Added by nobu (Nobuyoshi Nakada) about 3 years ago

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.

Revision 54189
Added by nobu (Nobuyoshi Nakada) about 3 years ago

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.

Revision 54189
Added by nobu (Nobuyoshi Nakada) about 3 years ago

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.

Revision 54189
Added by nobu (Nobuyoshi Nakada) about 3 years ago

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.

Revision a49068f1
Added by nobu (Nobuyoshi Nakada) almost 3 years ago

error.c: fix newline in syntax error

  • error.c (rb_syntax_error_append): fix newline in syntax error message to the beginning, not after file name and line number. [Feature #11951]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55878 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 55878
Added by nobu (Nobuyoshi Nakada) almost 3 years ago

error.c: fix newline in syntax error

  • error.c (rb_syntax_error_append): fix newline in syntax error message to the beginning, not after file name and line number. [Feature #11951]

Revision 55878
Added by nobu (Nobuyoshi Nakada) almost 3 years ago

error.c: fix newline in syntax error

  • error.c (rb_syntax_error_append): fix newline in syntax error message to the beginning, not after file name and line number. [Feature #11951]

Revision 55878
Added by nobu (Nobuyoshi Nakada) almost 3 years ago

error.c: fix newline in syntax error

  • error.c (rb_syntax_error_append): fix newline in syntax error message to the beginning, not after file name and line number. [Feature #11951]

Revision 55878
Added by nobu (Nobuyoshi Nakada) almost 3 years ago

error.c: fix newline in syntax error

  • error.c (rb_syntax_error_append): fix newline in syntax error message to the beginning, not after file name and line number. [Feature #11951]

History

#1

Updated by nobu (Nobuyoshi Nakada) over 3 years ago

  • Is duplicate of Feature #11868: Proposal for RubyVM::InstructionSequence.compile to return an object containing the syntax error information currently written to STDERR added
#2

Updated by nobu (Nobuyoshi Nakada) about 3 years ago

  • Is duplicate of deleted (Feature #11868: Proposal for RubyVM::InstructionSequence.compile to return an object containing the syntax error information currently written to STDERR)
#3

Updated by nobu (Nobuyoshi Nakada) about 3 years ago

  • Related to Feature #11868: Proposal for RubyVM::InstructionSequence.compile to return an object containing the syntax error information currently written to STDERR added
#5

Updated by nobu (Nobuyoshi Nakada) about 3 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.

Also available in: Atom PDF