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

Grape 2.1.x fail to compile, NoMethodError: undefined method []' for nil in grape/dsl/inside_route.rb:421:in route' #2491

Closed
DonMat opened this issue Aug 31, 2024 · 8 comments · Fixed by #2492

Comments

@DonMat
Copy link

DonMat commented Aug 31, 2024

I've an issue after upgrade Grape from 2.0 to 2.1.x
My apps setup. The same error is produced on:
Ruby 3.3.4, Rails 7.2
Ruby 3.3.1 , Rails 7.0.8.4, 7.1.3.3
Official repo Grape on Rails behaves the same after upgrade Grape locally to 2.1.3

Steps to reproduce:

  • Use any of Ruby 3.x and Rails 7.x
  • Use Twitter::API example form readme
  • Try to compile Twitter::API.compile! with Grape 2.0
  • Upgrade Grape to 2.1.*
  • Try to compile Twitter::API.compile!
Twitter::Api.compile!
An error occurred when inspecting the object: #<NoMethodError: undefined method `[]' for nil>
An error occurred when running Kernel#inspect: #<NoMethodError: undefined method `[]' for nil>
/Users/rails/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/grape-2.1.3/lib/grape/dsl/inside_route.rb:423:in `route'
/Users/rails/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/grape-2.1.3/lib/grape/endpoint.rb:409:in `inspect'
/Users/rails/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/activesupport-7.2.1/lib/active_support/ordered_options.rb:69:in `inspect'
/Users/rails/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/activesupport-7.2.1/lib/active_support/ordered_options.rb:69:in `inspect'
/Users/rails/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/irb-1.14.0/lib/irb/inspector.rb:101:in `inspect'
/Users/rails/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/irb-1.14.0/lib/irb/inspector.rb:101:in `inspect'
/Users/rails/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/irb-1.14.0/lib/irb/inspector.rb:101:in `inspect'
/Users/rails/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/irb-1.14.0/lib/irb/inspector.rb:101:in `inspect'
/Users/rails/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/irb-1.14.0/lib/irb/inspector.rb:101:in `bind_call'
/Users/rails/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/irb-1.14.0/lib/irb/inspector.rb:101:in `rescue in inspect_value'
/Users/rails/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/irb-1.14.0/lib/irb/inspector.rb:95:in `inspect_value'
/Users/rails/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/irb-1.14.0/lib/irb/context.rb:639:in `inspect_last_value'
/Users/rails/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/irb-1.14.0/lib/irb.rb:1395:in `output_value'
/Users/rails/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/irb-1.14.0/lib/irb.rb:1057:in `block (2 levels) in eval_input'
/Users/rails/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/irb-1.14.0/lib/irb.rb:1388:in `signal_status'
/Users/rails/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/irb-1.14.0/lib/irb.rb:1041:in `block in eval_input'
/Users/rails/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/irb-1.14.0/lib/irb.rb:1120:in `block in each_top_level_statement'
<internal:kernel>:187:in `loop'
/Users/rails/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/irb-1.14.0/lib/irb.rb:1117:in `each_top_level_statement'
/Users/rails/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/irb-1.14.0/lib/irb.rb:1040:in `eval_input'
/Users/rails/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/irb-1.14.0/lib/irb.rb:1021:in `block in run'
/Users/rails/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/irb-1.14.0/lib/irb.rb:1020:in `catch'
/Users/rails/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/irb-1.14.0/lib/irb.rb:1020:in `run'
/Users/rails/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/railties-7.2.1/lib/rails/commands/console/irb_console.rb:119:in `start'
/Users/rails/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/railties-7.2.1/lib/rails/commands/console/console_command.rb:59:in `start'
/Users/rails/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/railties-7.2.1/lib/rails/commands/console/console_command.rb:8:in `start'
/Users/rails/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/railties-7.2.1/lib/rails/commands/console/console_command.rb:87:in `perform'
/Users/rails/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/thor-1.3.2/lib/thor/command.rb:28:in `run'
/Users/rails/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/thor-1.3.2/lib/thor/invocation.rb:127:in `invoke_command'
/Users/rails/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/railties-7.2.1/lib/rails/command/base.rb:178:in `invoke_command'
/Users/rails/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/thor-1.3.2/lib/thor.rb:538:in `dispatch'
/Users/rails/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/railties-7.2.1/lib/rails/command/base.rb:73:in `perform'
/Users/rails/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/railties-7.2.1/lib/rails/command.rb:71:in `block in invoke'
/Users/rails/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/railties-7.2.1/lib/rails/command.rb:149:in `with_argv'
/Users/rails/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/railties-7.2.1/lib/rails/command.rb:69:in `invoke'
/Users/rails/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/railties-7.2.1/lib/rails/commands.rb:18:in `<main>'
/Users/rails/.rbenv/versions/3.3.1/lib/ruby/3.3.0/bundled_gems.rb:74:in `require'
/Users/rails/.rbenv/versions/3.3.1/lib/ruby/3.3.0/bundled_gems.rb:74:in `block (2 levels) in replace_require'
/Users/rails/.rbenv/versions/3.3.1/lib/ruby/gems/3.3.0/gems/bootsnap-1.18.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
bin/rails:4:in `<main>'
@dblock
Copy link
Member

dblock commented Aug 31, 2024

This is similar to #1956 I believe, what version of Rack do you have? Can you put up a repro where this happens please?

I've upgraded grape to 2.x in ruby-grape/grape-on-rails#65 and it worked ok.

@dblock dblock added the bug? label Aug 31, 2024
@DonMat
Copy link
Author

DonMat commented Aug 31, 2024

@dblock I have rack 3.1.7 on Rails 7.2. Something weird is here. Error exists in rails console but api works well on rails server. grape-swagger-rails produce valid swagger.

This is my Gemfil.lock


GEM
  remote: https://rubygems.org/
  specs:
    actioncable (7.2.0)
      actionpack (= 7.2.0)
      activesupport (= 7.2.0)
      nio4r (~> 2.0)
      websocket-driver (>= 0.6.1)
      zeitwerk (~> 2.6)
    actionmailbox (7.2.0)
      actionpack (= 7.2.0)
      activejob (= 7.2.0)
      activerecord (= 7.2.0)
      activestorage (= 7.2.0)
      activesupport (= 7.2.0)
      mail (>= 2.8.0)
    actionmailer (7.2.0)
      actionpack (= 7.2.0)
      actionview (= 7.2.0)
      activejob (= 7.2.0)
      activesupport (= 7.2.0)
      mail (>= 2.8.0)
      rails-dom-testing (~> 2.2)
    actionpack (7.2.0)
      actionview (= 7.2.0)
      activesupport (= 7.2.0)
      nokogiri (>= 1.8.5)
      racc
      rack (>= 2.2.4, < 3.2)
      rack-session (>= 1.0.1)
      rack-test (>= 0.6.3)
      rails-dom-testing (~> 2.2)
      rails-html-sanitizer (~> 1.6)
      useragent (~> 0.16)
    actiontext (7.2.0)
      actionpack (= 7.2.0)
      activerecord (= 7.2.0)
      activestorage (= 7.2.0)
      activesupport (= 7.2.0)
      globalid (>= 0.6.0)
      nokogiri (>= 1.8.5)
    actionview (7.2.0)
      activesupport (= 7.2.0)
      builder (~> 3.1)
      erubi (~> 1.11)
      rails-dom-testing (~> 2.2)
      rails-html-sanitizer (~> 1.6)
    activejob (7.2.0)
      activesupport (= 7.2.0)
      globalid (>= 0.3.6)
    activemodel (7.2.0)
      activesupport (= 7.2.0)
    activerecord (7.2.0)
      activemodel (= 7.2.0)
      activesupport (= 7.2.0)
      timeout (>= 0.4.0)
    activestorage (7.2.0)
      actionpack (= 7.2.0)
      activejob (= 7.2.0)
      activerecord (= 7.2.0)
      activesupport (= 7.2.0)
      marcel (~> 1.0)
    activesupport (7.2.0)
      base64
      bigdecimal
      concurrent-ruby (~> 1.0, >= 1.3.1)
      connection_pool (>= 2.2.5)
      drb
      i18n (>= 1.6, < 2)
      logger (>= 1.4.2)
      minitest (>= 5.1)
      securerandom (>= 0.3)
      tzinfo (~> 2.0, >= 2.0.5)
    api-pagination (6.0.0)
    ast (2.4.2)
    awesome_print (1.9.2)
    backport (1.2.0)
    base64 (0.2.0)
    benchmark (0.3.0)
    bigdecimal (3.1.8)
    bindex (0.8.1)
    bootsnap (1.18.4)
      msgpack (~> 1.2)
    brakeman (6.1.2)
      racc
    builder (3.3.0)
    bullet (7.2.0)
      activesupport (>= 3.0.0)
      uniform_notifier (~> 1.11)
    concurrent-ruby (1.3.4)
    connection_pool (2.4.1)
    crass (1.0.6)
    database_cleaner (2.0.2)
      database_cleaner-active_record (>= 2, < 3)
    database_cleaner-active_record (2.2.0)
      activerecord (>= 5.a)
      database_cleaner-core (~> 2.0.0)
    database_cleaner-core (2.0.1)
    date (3.3.4)
    debug (1.9.2)
      irb (~> 1.10)
      reline (>= 0.3.8)
    diff-lcs (1.5.1)
    docile (1.4.1)
    drb (2.2.1)
    dry-core (1.0.1)
      concurrent-ruby (~> 1.0)
      zeitwerk (~> 2.6)
    dry-inflector (1.1.0)
    dry-logic (1.5.0)
      concurrent-ruby (~> 1.0)
      dry-core (~> 1.0, < 2)
      zeitwerk (~> 2.6)
    dry-types (1.7.2)
      bigdecimal (~> 3.0)
      concurrent-ruby (~> 1.0)
      dry-core (~> 1.0)
      dry-inflector (~> 1.0)
      dry-logic (~> 1.4)
      zeitwerk (~> 2.6)
    e2mmap (0.1.0)
    erubi (1.13.0)
    factory_bot (6.4.6)
      activesupport (>= 5.0.0)
    factory_bot_rails (6.4.3)
      factory_bot (~> 6.4)
      railties (>= 5.0.0)
    faraday (2.11.0)
      faraday-net_http (>= 2.0, < 3.4)
      logger
    faraday-multipart (1.0.4)
      multipart-post (~> 2)
    faraday-net_http (3.3.0)
      net-http
    globalid (1.2.1)
      activesupport (>= 6.1)
    grape (2.1.3)
      activesupport (>= 6)
      dry-types (>= 1.1)
      mustermann-grape (~> 1.1.0)
      rack (>= 2)
      zeitwerk
    grape-entity (1.0.1)
      activesupport (>= 3.0.0)
      multi_json (>= 1.3.2)
    grape-swagger (2.1.0)
      grape (>= 1.7, < 3.0)
      rack-test (~> 2)
    grape-swagger-entity (0.5.4)
      grape-entity (~> 1)
      grape-swagger (~> 2)
    grape-swagger-rails (0.5.0)
      railties (>= 6.0.6.1)
    grape_on_rails_routes (0.3.2)
      rails (>= 3.1.1)
    i18n (1.14.5)
      concurrent-ruby (~> 1.0)
    importmap-rails (2.0.1)
      actionpack (>= 6.0.0)
      activesupport (>= 6.0.0)
      railties (>= 6.0.0)
    io-console (0.7.2)
    irb (1.14.0)
      rdoc (>= 4.0.0)
      reline (>= 0.4.2)
    jaro_winkler (1.6.0)
    jbuilder (2.12.0)
      actionview (>= 5.0.0)
      activesupport (>= 5.0.0)
    json (2.7.2)
    kramdown (2.4.0)
      rexml
    kramdown-parser-gfm (1.1.0)
      kramdown (~> 2.0)
    language_server-protocol (3.17.0.3)
    logger (1.6.0)
    loofah (2.22.0)
      crass (~> 1.0.2)
      nokogiri (>= 1.12.0)
    mail (2.8.1)
      mini_mime (>= 0.1.1)
      net-imap
      net-pop
      net-smtp
    marcel (1.0.4)
    mini_mime (1.1.5)
    minitest (5.25.1)
    msgpack (1.7.2)
    multi_json (1.15.0)
    multipart-post (2.4.1)
    mustermann (3.0.2)
      ruby2_keywords (~> 0.0.1)
    mustermann-grape (1.1.0)
      mustermann (>= 1.0.0)
    net-http (0.4.1)
      uri
    net-imap (0.4.14)
      date
      net-protocol
    net-pop (0.1.2)
      net-protocol
    net-protocol (0.2.2)
      timeout
    net-smtp (0.5.0)
      net-protocol
    nio4r (2.7.3)
    nokogiri (1.16.7-aarch64-linux)
      racc (~> 1.4)
    nokogiri (1.16.7-arm-linux)
      racc (~> 1.4)
    nokogiri (1.16.7-arm64-darwin)
      racc (~> 1.4)
    nokogiri (1.16.7-x86-linux)
      racc (~> 1.4)
    nokogiri (1.16.7-x86_64-darwin)
      racc (~> 1.4)
    nokogiri (1.16.7-x86_64-linux)
      racc (~> 1.4)
    pagy (9.0.6)
    parallel (1.26.3)
    parser (3.3.4.2)
      ast (~> 2.4.1)
      racc
    pg (1.5.7)
    psych (5.1.2)
      stringio
    puma (6.4.2)
      nio4r (~> 2.0)
    racc (1.8.1)
    rack (3.1.7)
    rack-cors (2.0.2)
      rack (>= 2.0.0)
    rack-session (2.0.0)
      rack (>= 3.0.0)
    rack-test (2.1.0)
      rack (>= 1.3)
    rackup (2.1.0)
      rack (>= 3)
      webrick (~> 1.8)
    rails (7.2.0)
      actioncable (= 7.2.0)
      actionmailbox (= 7.2.0)
      actionmailer (= 7.2.0)
      actionpack (= 7.2.0)
      actiontext (= 7.2.0)
      actionview (= 7.2.0)
      activejob (= 7.2.0)
      activemodel (= 7.2.0)
      activerecord (= 7.2.0)
      activestorage (= 7.2.0)
      activesupport (= 7.2.0)
      bundler (>= 1.15.0)
      railties (= 7.2.0)
    rails-dom-testing (2.2.0)
      activesupport (>= 5.0.0)
      minitest
      nokogiri (>= 1.6)
    rails-html-sanitizer (1.6.0)
      loofah (~> 2.21)
      nokogiri (~> 1.14)
    railties (7.2.0)
      actionpack (= 7.2.0)
      activesupport (= 7.2.0)
      irb (~> 1.13)
      rackup (>= 1.0.0)
      rake (>= 12.2)
      thor (~> 1.0, >= 1.2.2)
      zeitwerk (~> 2.6)
    rainbow (3.1.1)
    rake (13.2.1)
    rbs (2.8.4)
    rdoc (6.7.0)
      psych (>= 4.0.0)
    regexp_parser (2.9.2)
    reline (0.5.9)
      io-console (~> 0.5)
    reverse_markdown (2.1.1)
      nokogiri
    rexml (3.3.6)
      strscan
    rspec-core (3.13.0)
      rspec-support (~> 3.13.0)
    rspec-expectations (3.13.2)
      diff-lcs (>= 1.2.0, < 2.0)
      rspec-support (~> 3.13.0)
    rspec-mocks (3.13.1)
      diff-lcs (>= 1.2.0, < 2.0)
      rspec-support (~> 3.13.0)
    rspec-rails (6.1.4)
      actionpack (>= 6.1)
      activesupport (>= 6.1)
      railties (>= 6.1)
      rspec-core (~> 3.13)
      rspec-expectations (~> 3.13)
      rspec-mocks (~> 3.13)
      rspec-support (~> 3.13)
    rspec-support (3.13.1)
    rubocop (1.65.1)
      json (~> 2.3)
      language_server-protocol (>= 3.17.0)
      parallel (~> 1.10)
      parser (>= 3.3.0.2)
      rainbow (>= 2.2.2, < 4.0)
      regexp_parser (>= 2.4, < 3.0)
      rexml (>= 3.2.5, < 4.0)
      rubocop-ast (>= 1.31.1, < 2.0)
      ruby-progressbar (~> 1.7)
      unicode-display_width (>= 2.4.0, < 3.0)
    rubocop-ast (1.32.1)
      parser (>= 3.3.1.0)
    rubocop-minitest (0.35.1)
      rubocop (>= 1.61, < 2.0)
      rubocop-ast (>= 1.31.1, < 2.0)
    rubocop-performance (1.21.1)
      rubocop (>= 1.48.1, < 2.0)
      rubocop-ast (>= 1.31.1, < 2.0)
    rubocop-rails (2.25.1)
      activesupport (>= 4.2.0)
      rack (>= 1.1)
      rubocop (>= 1.33.0, < 2.0)
      rubocop-ast (>= 1.31.1, < 2.0)
    rubocop-rails-omakase (1.0.0)
      rubocop
      rubocop-minitest
      rubocop-performance
      rubocop-rails
    ruby-progressbar (1.13.0)
    ruby2_keywords (0.0.5)
    securerandom (0.3.1)
    shoulda-matchers (6.4.0)
      activesupport (>= 5.2.0)
    simplecov (0.22.0)
      docile (~> 1.1)
      simplecov-html (~> 0.11)
      simplecov_json_formatter (~> 0.1)
    simplecov-html (0.12.3)
    simplecov_json_formatter (0.1.4)
    solargraph (0.50.0)
      backport (~> 1.2)
      benchmark
      bundler (~> 2.0)
      diff-lcs (~> 1.4)
      e2mmap
      jaro_winkler (~> 1.5)
      kramdown (~> 2.3)
      kramdown-parser-gfm (~> 1.1)
      parser (~> 3.0)
      rbs (~> 2.0)
      reverse_markdown (~> 2.0)
      rubocop (~> 1.38)
      thor (~> 1.0)
      tilt (~> 2.0)
      yard (~> 0.9, >= 0.9.24)
    sprockets (4.2.1)
      concurrent-ruby (~> 1.0)
      rack (>= 2.2.4, < 4)
    sprockets-rails (3.5.2)
      actionpack (>= 6.1)
      activesupport (>= 6.1)
      sprockets (>= 3.0.0)
    stimulus-rails (1.3.4)
      railties (>= 6.0.0)
    stringio (3.1.1)
    strscan (3.1.0)
    thor (1.3.1)
    tilt (2.4.0)
    timeout (0.4.1)
    turbo-rails (2.0.6)
      actionpack (>= 6.0.0)
      activejob (>= 6.0.0)
      railties (>= 6.0.0)
    tzinfo (2.0.6)
      concurrent-ruby (~> 1.0)
    unicode-display_width (2.5.0)
    uniform_notifier (1.16.0)
    uri (0.13.0)
    useragent (0.16.10)
    web-console (4.2.1)
      actionview (>= 6.0.0)
      activemodel (>= 6.0.0)
      bindex (>= 0.4.0)
      railties (>= 6.0.0)
    webrick (1.8.1)
    websocket-driver (0.7.6)
      websocket-extensions (>= 0.1.0)
    websocket-extensions (0.1.5)
    yard (0.9.36)
    zeitwerk (2.6.17)

PLATFORMS
  aarch64-linux
  arm-linux
  arm64-darwin
  x86-linux
  x86_64-darwin
  x86_64-linux

DEPENDENCIES
  api-pagination
  awesome_print
  bootsnap
  brakeman
  bullet
  database_cleaner
  debug
  factory_bot_rails
  grape (~> 2.0)
  grape-entity
  grape-swagger
  grape-swagger-entity (~> 0.3)
  grape-swagger-rails
  grape_on_rails_routes
  importmap-rails
  jbuilder
  pagy (~> 9.0)
  pg (~> 1.1)
  puma (>= 5.0)
  rack-cors (~> 2.0)
  rails (~> 7.2.0)
  rspec-rails (~> 6.1.0)
  rubocop
  rubocop-performance
  rubocop-rails
  rubocop-rails-omakase
  shoulda-matchers (~> 6.0)
  simplecov
  solargraph
  sprockets-rails
  stimulus-rails
  turbo-rails
  tzinfo-data
  web-console

BUNDLED WITH
   2.5.17

@DonMat
Copy link
Author

DonMat commented Aug 31, 2024

@dblock I've checked your ruby-grape/grape-on-rails#65 and the problem exists in console.

In code

env[Grape::Env::GRAPE_ROUTING_ARGS][:route_info]

env is nil

@ericproulx
Copy link
Contributor

ericproulx commented Sep 1, 2024

#2444 introduced the bug.

@ericproulx
Copy link
Contributor

ericproulx commented Sep 1, 2024

@DonMat the error occurs only when compiling in console ? When compiling in console, it calls inspect on endpoint and it fails.

@dblock
Copy link
Member

dblock commented Sep 1, 2024

Looks like we now understand why it happens.

Can either of you help with an integration test that is a big higher level than the fix in #2492? I'd like a test that reproduces "it doesn't work in console" in https://github.com/ruby-grape/grape-swagger-rails and here, so we can catch similar regressions easier.

@dblock
Copy link
Member

dblock commented Sep 2, 2024

@DonMat test w/HEAD please?

@DonMat
Copy link
Author

DonMat commented Sep 2, 2024

@dblock It work like a charm. Thank you for very fast fix.
Tested on:

  remote: git@github.com:ruby-grape/grape.git
  revision: 1cf4a801efc22e65c4fb342ead57fe3c428a4b8d
  branch: master

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants