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

Error: undefined method `last' for nil:NilClass (NoMethodError) #1

Open
elado opened this issue Dec 1, 2014 · 3 comments
Open

Error: undefined method `last' for nil:NilClass (NoMethodError) #1

elado opened this issue Dec 1, 2014 · 3 comments

Comments

@elado
Copy link

elado commented Dec 1, 2014

I'm running my app (not on Rails, just config.ru) and getting this:

/gems/grape-reload-0.0.4/lib/ripper/extract_constants.rb:352:in `initialize': undefined method `last' for nil:NilClass (NoMethodError)
    from /gems/grape-reload-0.0.4/lib/ripper/extract_constants.rb:131:in `new'
    from /gems/grape-reload-0.0.4/lib/ripper/extract_constants.rb:131:in `node_for'
    from /gems/grape-reload-0.0.4/lib/ripper/extract_constants.rb:171:in `block in initialize'
    from /gems/grape-reload-0.0.4/lib/ripper/extract_constants.rb:171:in `map'
    from /gems/grape-reload-0.0.4/lib/ripper/extract_constants.rb:171:in `initialize'
    from /gems/grape-reload-0.0.4/lib/ripper/extract_constants.rb:131:in `new'
    from /gems/grape-reload-0.0.4/lib/ripper/extract_constants.rb:131:in `node_for'
    from /gems/grape-reload-0.0.4/lib/ripper/extract_constants.rb:393:in `extract_constants'
    from /gems/grape-reload-0.0.4/lib/grape/reload/dependency_map.rb:27:in `block in initialize'
    from /gems/grape-reload-0.0.4/lib/grape/reload/dependency_map.rb:27:in `map'
    from /gems/grape-reload-0.0.4/lib/grape/reload/dependency_map.rb:27:in `initialize'
    from /gems/grape-reload-0.0.4/lib/grape/reload/dependency_map.rb:129:in `new'
    from /gems/grape-reload-0.0.4/lib/grape/reload/dependency_map.rb:129:in `initialize'
    from /gems/grape-reload-0.0.4/lib/grape/reload/rack_builder.rb:73:in `new'
    from /gems/grape-reload-0.0.4/lib/grape/reload/rack_builder.rb:73:in `boot!'

Refers to @module_name = args.find{|a| a.first == :const_ref}.last[1]

The args is:

{
  :args => [
    [0] [
      [0] :const_path_ref,
      [1] [
        [0] :const_path_ref,
        [1] [
          [0] :var_ref,
          [1] [
            [0] :@const,
            [1] "CarrierWave",
            [2] [
              [0] 54,
              [1] 7
            ]
          ]
        ],
        [2] [
          [0] :@const,
          [1] "Sequel",
          [2] [
            [0] 54,
            [1] 20
          ]
        ]
      ],
      [2] [
        [0] :@const,
        [1] "Validations",
        [2] [
          [0] 54,
          [1] 28
        ]
      ]
    ],
    [1] [
      [0] :bodystmt,
      [1] [
        [0] [
          [0] :void_stmt
        ],
        [1] [
          [0] :def,
          [1] [
            [0] :@ident,
            [1] "validate",
            [2] [
              [0] 55,
              [1] 6
            ]
          ],
          [2] [
            [0] :params,
            [1] nil,
            [2] nil,
            [3] nil,
            [4] nil,
            [5] nil,
            [6] nil,
            [7] nil
          ],
          [3] [
            [0] :bodystmt,
            [1] [
              [0] [
                [0] :zsuper
              ],
              [1] [
                [0] :method_add_block,
                [1] [
                  [0] :call,
                  [1] [
                    [0] :call,
                    [1] [
                      [0] :call,
                      [1] [
                        [0] :var_ref,
                        [1] [
                          [0] :@kw,
                          [1] "self",
                          [2] [
                            [0] 57,
                            [1] 4
                          ]
                        ]
                      ],
                      [2] :".",
                      [3] [
                        [0] :@ident,
                        [1] "class",
                        [2] [
                          [0] 57,
                          [1] 9
                        ]
                      ]
                    ],
                    [2] :".",
                    [3] [
                      [0] :@ident,
                      [1] "uploaders",
                      [2] [
                        [0] 57,
                        [1] 15
                      ]
                    ]
                  ],
                  [2] :".",
                  [3] [
                    [0] :@ident,
                    [1] "each_key",
                    [2] [
                      [0] 57,
                      [1] 25
                    ]
                  ]
                ],
                [2] [
                  [0] :do_block,
                  [1] [
                    [0] :block_var,
                    [1] [
                      [0] :params,
                      [1] [
                        [0] [
                          [0] :@ident,
                          [1] "column",
                          [2] [
                            [0] 57,
                            [1] 38
                          ]
                        ]
                      ],
                      [2] nil,
                      [3] nil,
                      [4] nil,
                      [5] nil,
                      [6] nil,
                      [7] nil
                    ],
                    [2] false
                  ],
                  [2] [
                    [0] [
                      [0] :if_mod,
                      [1] [
                        [0] :method_add_arg,
                        [1] [
                          [0] :fcall,
                          [1] [
                            [0] :@ident,
                            [1] "send",
                            [2] [
                              [0] 58,
                              [1] 39
                            ]
                          ]
                        ],
                        [2] [
                          [0] :arg_paren,
                          [1] [
                            [0] :args_add_block,
                            [1] [
                              [0] [
                                [0] :string_literal,
                                [1] [
                                  [0] :string_content,
                                  [1] [
                                    [0] :string_embexpr,
                                    [1] [
                                      [0] [
                                        [0] :var_ref,
                                        [1] [
                                          [0] :@ident,
                                          [1] "column",
                                          [2] [
                                            [0] 58,
                                            [1] 47
                                          ]
                                        ]
                                      ]
                                    ]
                                  ],
                                  [2] [
                                    [0] :@tstring_content,
                                    [1] "_integrity_error",
                                    [2] [
                                      [0] 58,
                                      [1] 54
                                    ]
                                  ]
                                ]
                              ]
                            ],
                            [2] false
                          ]
                        ]
                      ],
                      [2] [
                        [0] :method_add_arg,
                        [1] [
                          [0] :call,
                          [1] [
                            [0] :vcall,
                            [1] [
                              [0] :@ident,
                              [1] "errors",
                              [2] [
                                [0] 58,
                                [1] 6
                              ]
                            ]
                          ],
                          [2] :".",
                          [3] [
                            [0] :@ident,
                            [1] "add",
                            [2] [
                              [0] 58,
                              [1] 13
                            ]
                          ]
                        ],
                        [2] [
                          [0] :arg_paren,
                          [1] [
                            [0] :args_add_block,
                            [1] [
                              [0] [
                                [0] :var_ref,
                                [1] [
                                  [0] :@ident,
                                  [1] "column",
                                  [2] [
                                    [0] 58,
                                    [1] 17
                                  ]
                                ]
                              ],
                              [1] [
                                [0] :string_literal,
                                [1] [
                                  [0] :string_content,
                                  [1] [
                                    [0] :@tstring_content,
                                    [1] "invalid",
                                    [2] [
                                      [0] 58,
                                      [1] 26
                                    ]
                                  ]
                                ]
                              ]
                            ],
                            [2] false
                          ]
                        ]
                      ]
                    ]
                  ]
                ]
              ]
            ],
            [2] nil,
            [3] nil,
            [4] nil
          ]
        ]
      ],
      [2] nil,
      [3] nil,
      [4] nil
    ]
  ]
}

It refers to source of gem carrierwave-sequel.

@AMar4enko
Copy link
Owner

Wow, looks weird.
Can you show you config.ru and Gemfile? It's should't even try to parse gems sources.

@elado
Copy link
Author

elado commented Dec 2, 2014

My bad, it was referring my code, which is

module CarrierWave::Sequel::Validations
  def validate
    super
    self.class.uploaders.each_key do |column|
      errors.add(column, 'invalid') if send("#{column}_integrity_error")
    end
  end
end

Once removed it failed on something else, similar: an already-defiend module with an instance method.

My config.ru is something like:

require_relative './server'
require 'grape/reload'

Grape::RackBuilder.setup do
  logger Logger.new(STDOUT)
  add_source_path File.expand_path('**/*.rb', __dir__)
  reload_threshold 1
  force_reloading true
  mount 'MyApp::API', to: '/'
end

run Grape::RackBuilder.boot!.application

@AMar4enko
Copy link
Owner

Can you add test reproducing error?
BTW, in readme i describe such potential issue:

# Bad
class AlreadyDefined
# Here is your code to patch class
end

# Good
AlreadyDefined.class_eval do 
# Here is your code to patch class
end

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

No branches or pull requests

2 participants