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

Problem requiring "prism/translation/parser33" #2803

Closed
domingo2000 opened this issue May 11, 2024 · 0 comments · Fixed by #2804
Closed

Problem requiring "prism/translation/parser33" #2803

domingo2000 opened this issue May 11, 2024 · 0 comments · Fixed by #2804

Comments

@domingo2000
Copy link

I found a bug when loading the "prism/translation/parser33" using rubocop with bundler. I could reproduce the same error only requiring prism abd parser33 so the problem is actually from the prism gem parser and not from rubocop.

Current behaviour

When runing

require "prism"
require "prism/translation/parser33"

it throws error because the file versions/3.3.1/lib/ruby/gems/3.3.0/gems/prism-0.29.0/lib/prism/translation/parser.rb cannot load the parser gem. Here is the full log

<internal:/home/domingo/.rbenv/versions/3.3.1/lib/ruby/3.3.0/rubygems/core_ext/kernel_require.rb>:136:in `require': cannot load such file -- parser (LoadError)
        from <internal:/home/domingo/.rbenv/versions/3.3.1/lib/ruby/3.3.0/rubygems/core_ext/kernel_require.rb>:136:in `require'
        from /home/domingo/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/prism-0.29.0/lib/prism/translation/parser.rb:3:in `<top (required)>'
        from <internal:/home/domingo/.rbenv/versions/3.3.1/lib/ruby/3.3.0/rubygems/core_ext/kernel_require.rb>:136:in `require'
        from <internal:/home/domingo/.rbenv/versions/3.3.1/lib/ruby/3.3.0/rubygems/core_ext/kernel_require.rb>:136:in `require'
        from /home/domingo/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/prism-0.29.0/lib/prism/translation/parser33.rb:6:in `<module:Translation>'
        from /home/domingo/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/prism-0.29.0/lib/prism/translation/parser33.rb:4:in `<module:Prism>'
        from /home/domingo/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/prism-0.29.0/lib/prism/translation/parser33.rb:3:in `<top (required)>'
        from <internal:/home/domingo/.rbenv/versions/3.3.1/lib/ruby/3.3.0/rubygems/core_ext/kernel_require.rb>:136:in `require'
        from <internal:/home/domingo/.rbenv/versions/3.3.1/lib/ruby/3.3.0/rubygems/core_ext/kernel_require.rb>:136:in `require'
        from main.rb:2:in `<main>'

This affects the running of rubocop when running with bundler. Here is all my enviroment information to reproduce the problem

Ruby Version: ruby 3.3.1 (2024-04-23 revision c56cd86388) [x86_64-linux]
OS: Ubuntu 22.04.3 LTS (In Windows 10 WSL)

Gemfile:

# frozen_string_literal: true

source "https://rubygems.org"

gem "prism", "~> 0.29.0"

Gemfile.lock:

GEM
  remote: https://rubygems.org/
  specs:
    prism (0.29.0)

PLATFORMS
  ruby
  x86_64-linux

DEPENDENCIES
  prism (~> 0.29.0)

BUNDLED WITH
   2.5.9
@domingo2000 domingo2000 changed the title Problem requiring "prism/translation/parser33" using bundler. Problem requiring "prism/translation/parser33" May 12, 2024
koic added a commit to koic/prism that referenced this issue May 13, 2024
Resolves ruby#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.
```
matzbot pushed a commit to ruby/ruby that referenced this issue May 13, 2024
…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
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 a pull request may close this issue.

1 participant