Skip to content

Catch RuntimeError when parsing #65

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

Merged
merged 1 commit into from
Dec 30, 2015
Merged

Catch RuntimeError when parsing #65

merged 1 commit into from
Dec 30, 2015

Conversation

wfleming
Copy link
Contributor

RubyParser raises RuntimeError instead of anything more specific in
certain parse error contexts.

This presents a challenge for catching these, since many error types
(including Timeout::Error, which we don't want to catch) inherit from
RuntimeError. So I've had to shift from two rescue clauses to one
rescue clause that uses internal logic to decide if the error should
be re-raised.

Updated follow-up to #64, @codeclimate/review.

RubyParser raises `RuntimeError` instead of anything more specific in
certain parse error contexts.

This presents a challenge for catching these, since many error types
(including `Timeout::Error`, which we don't want to catch) inherit from
`RuntimeError`. So I've had to shift from two `rescue` clauses to one
`rescue` clause that uses internal logic to decide if the error should
be re-raised.
rescue => ex
$stderr.puts("#{ex.class} error occurred processing file #{file}: aborting.")
raise ex
if RESCUABLE_ERRORS.map { |klass| ex.instance_of?(klass) }.include?(true)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before anybody asks: ActiveSupport is not included in this gem, and it doesn't seem worth adding just for this.

@ABaldwinHunter
Copy link
Contributor

LGTM

wfleming added a commit that referenced this pull request Dec 30, 2015
@wfleming wfleming merged commit c8ecebe into master Dec 30, 2015
@wfleming wfleming deleted the will/runtimeerror branch December 30, 2015 18:20
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