Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ruby/prism] Add error handling for missing
parser
gem in `Prism::T…
…ranslation` Resolves ruby/prism#2803. This PR adds error handling for missing `parser` gem in `Prism::Translation`. The `parser` gem is a required runtime dependency when using `Prism::Translation::Parser`. But it is not required for other uses of Prism. To avoid unnecessary dependencies, it is not added as a `runtime_dependency` in the prism.gemspec. Instead, if the dependency is missing, instructions are given to add it to Gemfile. ## Before ```console $ bundle exec ruby -e 'require "prism"; require "prism/translation/parser33"' /Users/koic/.rbenv/versions/3.3.1/lib/ruby/3.3.0/bundled_gems.rb:74:in `require': cannot load such file -- parser (LoadError) from /Users/koic/.rbenv/versions/3.3.1/lib/ruby/3.3.0/bundled_gems.rb:74:in `block (2 levels) in replace_require' from /Users/koic/src/github.com/ruby/prism/lib/prism/translation/parser.rb:3:in `<top (required)>' from /Users/koic/.rbenv/versions/3.3.1/lib/ruby/3.3.0/bundled_gems.rb:74:in `require' from /Users/koic/.rbenv/versions/3.3.1/lib/ruby/3.3.0/bundled_gems.rb:74:in `block (2 levels) in replace_require' from /Users/koic/src/github.com/ruby/prism/lib/prism/translation/parser33.rb:6:in `<module:Translation>' from /Users/koic/src/github.com/ruby/prism/lib/prism/translation/parser33.rb:4:in `<module:Prism>' from /Users/koic/src/github.com/ruby/prism/lib/prism/translation/parser33.rb:3:in `<top (required)>' from /Users/koic/.rbenv/versions/3.3.1/lib/ruby/3.3.0/bundled_gems.rb:74:in `require' from /Users/koic/.rbenv/versions/3.3.1/lib/ruby/3.3.0/bundled_gems.rb:74:in `block (2 levels) in replace_require' from -e:1:in `<main>' ``` ## After ```console $ bundle exec ruby -e 'require "prism"; require "prism/translation/parser33"' Error: Unable to load parser. Add `gem "parser"` to your Gemfile. ``` ruby/prism@4880aec22d
- Loading branch information