Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add opal backtrace for compilation errors #1814

Merged
merged 1 commit into from
Sep 11, 2018

Conversation

elia
Copy link
Member

@elia elia commented May 2, 2018

Adds the location of the error inside the opal file that's being compiled for a better user experience.

Example:


opal:elia/opal-backtrace-for-compilation-errors ⤑ echo '1                                                                              ~/C/opal
                                                  2
                                                  3
                                                  4
                                                  5
                                                  def {}' > tmp/prova.rb
opal:elia/opal-backtrace-for-compilation-errors ⤑ bin/opal tmp/prova.rb                                                                ~/C/opal
tmp/prova.rb:6:5: error: unexpected token tLCURLY
tmp/prova.rb:6: def {}
tmp/prova.rb:6:     ^ 
Traceback (most recent call last):
	22: from bin/opal:4:in `<main>'
	21: from bin/opal:4:in `load'
	20: from /Users/elia/Code/opal/exe/opal:24:in `<top (required)>'
	19: from /Users/elia/Code/opal/lib/opal/cli.rb:66:in `run'
	18: from /Users/elia/Code/opal/lib/opal/cli.rb:78:in `builder'
	17: from /Users/elia/Code/opal/lib/opal/cli.rb:107:in `create_builder'
	16: from /Users/elia/Code/opal/lib/opal/cli.rb:146:in `evals_or_file'
	15: from /Users/elia/Code/opal/lib/opal/cli.rb:107:in `block in create_builder'
	14: from /Users/elia/Code/opal/lib/opal/builder.rb:95:in `build_str'
	13: from /Users/elia/Code/opal/lib/opal/builder_processors.rb:94:in `requires'
	12: from /Users/elia/Code/opal/lib/opal/builder_processors.rb:84:in `compiled'
	11: from /Users/elia/Code/opal/lib/opal/compiler.rb:173:in `compile'
	10: from /Users/elia/Code/opal/lib/opal/compiler.rb:187:in `parse'
	 9: from /Users/elia/Code/opal/lib/opal/compiler.rb:232:in `re_raise_with_location'
	 8: from /Users/elia/Code/opal/lib/opal/compiler.rb:187:in `block in parse'
	 7: from /Users/elia/.rvm/rubies/ruby-2.5.1/lib/ruby/gems/2.5.0/gems/parser-2.5.1.0/lib/parser/base.rb:214:in `tokenize'
	 6: from /Users/elia/Code/opal/lib/opal/parser/default_config.rb:32:in `parse'
	 5: from /Users/elia/.rvm/rubies/ruby-2.5.1/lib/ruby/gems/2.5.0/gems/parser-2.5.1.0/lib/parser/base.rb:167:in `parse'
	 4: from /Users/elia/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/racc/parser.rb:259:in `do_parse'
	 3: from /Users/elia/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/racc/parser.rb:259:in `_racc_do_parse_c'
	 2: from /Users/elia/.rvm/rubies/ruby-2.5.1/lib/ruby/gems/2.5.0/gems/parser-2.5.1.0/lib/parser/base.rb:262:in `on_error'
	 1: from /Users/elia/.rvm/rubies/ruby-2.5.1/lib/ruby/gems/2.5.0/gems/parser-2.5.1.0/lib/parser/diagnostic/engine.rb:73:in `process'
tmp/prova.rb:6:in `def {}': unexpected token tLCURLY (Opal::SyntaxError)
opal:elia/opal-backtrace-for-compilation-errors ⤑                           

@elia elia force-pushed the elia/opal-backtrace-for-compilation-errors branch 2 times, most recently from e747fe0 to 9184939 Compare May 14, 2018 22:59
@elia elia force-pushed the elia/opal-backtrace-for-compilation-errors branch from 9184939 to 3d7cccf Compare May 16, 2018 00:04
@elia elia force-pushed the elia/opal-backtrace-for-compilation-errors branch 3 times, most recently from 89a9cfa to 17f076c Compare September 4, 2018 21:05
An Opal::SyntaxError will be raised instead with the opal source
location as the first entry in the backtrace.
@elia elia force-pushed the elia/opal-backtrace-for-compilation-errors branch from 17f076c to 311e10d Compare September 4, 2018 21:06
@elia elia requested a review from iliabylich September 4, 2018 21:33
@elia elia merged commit b693abd into master Sep 11, 2018
elia added a commit that referenced this pull request Sep 11, 2018
@elia elia deleted the elia/opal-backtrace-for-compilation-errors branch September 11, 2018 20:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants