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

can't modify frozen Array #751

Closed
aspiers opened this issue Jun 14, 2014 · 12 comments
Closed

can't modify frozen Array #751

aspiers opened this issue Jun 14, 2014 · 12 comments

Comments

@aspiers
Copy link

aspiers commented Jun 14, 2014

I have the following config/initializers/omniauth.rb:

module MyApp
  class Application
    module OmniAuth
      def self.settings
        @@settings
      end

      @@yml_path = Rails.root.join("config", "omniauth", Rails.env + ".yml")
      @@settings = YAML.load(IO.read(@@yml_path))

      Rails.application.config.middleware.use ::OmniAuth::Builder do
        MyApp::Application::OmniAuth.settings.each do |service, secrets|
          provider service.to_sym, secrets['API_key'], secrets['app_secret']
        end
      end
    end
  end
end

but then this happens:

$ spring rake -T
Warning: You're using Rubygems 1.8.25 with Spring. Upgrade to at least Rubygems 2.1.0 and run `gem pristine --all` for better startup performance.
rake aborted!
can't modify frozen Array
/home/adam/.rvm/gems/ruby-1.9.3-p392@myapp/gems/actionpack-4.0.5/lib/action_dispatch/middleware/stack.rb:112:in `push'
/home/adam/.rvm/gems/ruby-1.9.3-p392@myapp/gems/actionpack-4.0.5/lib/action_dispatch/middleware/stack.rb:112:in `use'
/home/adam/rails/myapp/config/initializers/omniauth.rb:11:in `<module:OmniAuth>'
/home/adam/rails/myapp/config/initializers/omniauth.rb:3:in `<class:Application>'
/home/adam/rails/myapp/config/initializers/omniauth.rb:2:in `<module:Myapp>'
/home/adam/rails/myapp/config/initializers/omniauth.rb:1:in `<top (required)>'
/home/adam/.rvm/gems/ruby-1.9.3-p392@myapp/gems/activesupport-4.0.5/lib/active_support/dependencies.rb:229:in `require'
/home/adam/.rvm/gems/ruby-1.9.3-p392@myapp/gems/activesupport-4.0.5/lib/active_support/dependencies.rb:229:in `block in require'
/home/adam/.rvm/gems/ruby-1.9.3-p392@myapp/gems/activesupport-4.0.5/lib/active_support/dependencies.rb:214:in `load_dependency'
/home/adam/.rvm/gems/ruby-1.9.3-p392@myapp/gems/activesupport-4.0.5/lib/active_support/dependencies.rb:229:in `require'
/home/adam/rails/myapp/lib/tasks/test-user.rake:2:in `<top (required)>'
/home/adam/.rvm/gems/ruby-1.9.3-p392@myapp/gems/activesupport-4.0.5/lib/active_support/dependencies.rb:223:in `load'
/home/adam/.rvm/gems/ruby-1.9.3-p392@myapp/gems/activesupport-4.0.5/lib/active_support/dependencies.rb:223:in `block in load'
/home/adam/.rvm/gems/ruby-1.9.3-p392@myapp/gems/activesupport-4.0.5/lib/active_support/dependencies.rb:214:in `load_dependency'
/home/adam/.rvm/gems/ruby-1.9.3-p392@myapp/gems/activesupport-4.0.5/lib/active_support/dependencies.rb:223:in `load'
/home/adam/.rvm/gems/ruby-1.9.3-p392@myapp/gems/railties-4.0.5/lib/rails/engine.rb:641:in `block in run_tasks_blocks'
/home/adam/.rvm/gems/ruby-1.9.3-p392@myapp/gems/railties-4.0.5/lib/rails/engine.rb:641:in `each'
/home/adam/.rvm/gems/ruby-1.9.3-p392@myapp/gems/railties-4.0.5/lib/rails/engine.rb:641:in `run_tasks_blocks'
/home/adam/.rvm/gems/ruby-1.9.3-p392@myapp/gems/railties-4.0.5/lib/rails/application.rb:244:in `run_tasks_blocks'
/home/adam/.rvm/gems/ruby-1.9.3-p392@myapp/gems/railties-4.0.5/lib/rails/engine.rb:446:in `load_tasks'
/home/adam/.rvm/gems/ruby-1.9.3-p392@myapp/gems/railties-4.0.5/lib/rails/railtie/configurable.rb:30:in `method_missing'
/home/adam/rails/myapp/Rakefile:7:in `<top (required)>'
/home/adam/.rvm/gems/ruby-1.9.3-p392@myapp/gems/activesupport-4.0.5/lib/active_support/dependencies.rb:223:in `load'
/home/adam/.rvm/gems/ruby-1.9.3-p392@myapp/gems/activesupport-4.0.5/lib/active_support/dependencies.rb:223:in `block in load'
/home/adam/.rvm/gems/ruby-1.9.3-p392@myapp/gems/activesupport-4.0.5/lib/active_support/dependencies.rb:214:in `load_dependency'
/home/adam/.rvm/gems/ruby-1.9.3-p392@myapp/gems/activesupport-4.0.5/lib/active_support/dependencies.rb:223:in `load'
/home/adam/.rvm/gems/ruby-1.9.3-p392@myapp/gems/activesupport-4.0.5/lib/active_support/dependencies.rb:223:in `load'
/home/adam/.rvm/gems/ruby-1.9.3-p392@myapp/gems/activesupport-4.0.5/lib/active_support/dependencies.rb:223:in `block in load'
/home/adam/.rvm/gems/ruby-1.9.3-p392@myapp/gems/activesupport-4.0.5/lib/active_support/dependencies.rb:214:in `load_dependency'
/home/adam/.rvm/gems/ruby-1.9.3-p392@myapp/gems/activesupport-4.0.5/lib/active_support/dependencies.rb:223:in `load'
/home/adam/.rvm/gems/ruby-1.9.3-p392@myapp/gems/activesupport-4.0.5/lib/active_support/dependencies.rb:223:in `load'
/home/adam/.rvm/gems/ruby-1.9.3-p392@myapp/gems/activesupport-4.0.5/lib/active_support/dependencies.rb:223:in `block in load'
/home/adam/.rvm/gems/ruby-1.9.3-p392@myapp/gems/activesupport-4.0.5/lib/active_support/dependencies.rb:214:in `load_dependency'
/home/adam/.rvm/gems/ruby-1.9.3-p392@myapp/gems/activesupport-4.0.5/lib/active_support/dependencies.rb:223:in `load'
-e:1:in `<main>'
(See full trace by running task with --trace)
@aspiers
Copy link
Author

aspiers commented Jun 14, 2014

This looks similar to #668.

@tmilewski
Copy link
Member

I would first try restarting spring and trying again.

spring stop
spring rake -T

@aspiers
Copy link
Author

aspiers commented Jun 16, 2014

Doesn't make any difference; I already tried that.

@tmilewski
Copy link
Member

This doesn't appear to be an issue with OmniAuth but rather with the way in which the middleware is being adding.

Check out this GH issue for more information: smartinez87/exception_notification#165

Feel free to open this back up if you're still having issues.

@aspiers
Copy link
Author

aspiers commented Jun 16, 2014

I don't see anything in that other issue which explains what I'm doing wrong or what I could change to avoid this. Please can you elaborate? Like I said, I'm invoking Rails.application.config.middleware.use ::OmniAuth::Builder from config/initializers/omniauth.rb. Are you saying that I need to move that to config/environments/development.rb or something?

@aspiers
Copy link
Author

aspiers commented Jun 16, 2014

By the way, I don't have permission to reopen the issue.

@tmilewski tmilewski reopened this Jun 16, 2014
@subakva
Copy link

subakva commented Aug 15, 2014

TL;DR: This probably means that one of your providers is misconfigured. Check for missing requires, uninitialized environment variables, or invalid provider symbols.


I just ran into this issue. In my case, I had forgotten to require the provider gem that I was trying to configure. In the case issue above #668 the problem was that the wrong provider name was used.

It appears that something is swallowing exceptions from the OmniAuth builder, leaving the system in an invalid state which eventually leads to the unhelpful and misleading can't modify frozen Array error.

In the Omniauth Builder, it raises a LoadError when given an invalid provider. Changing that to RuntimeError (or any subclass of StandardError probably) allows the error to bubble up and provide a useful message. Although it does makes sense in a way to raise a LoadError here, it might be better to use a StandardError type. Maybe ArgumentError or a custom Omniauth::BuilderError?

See: https://github.com/intridea/omniauth/blob/master/lib/omniauth/builder.rb#L50

@rubycop
Copy link

rubycop commented Jun 8, 2016

@aspiers I have the same error with Omniauth. But It happens when I tried register middleware when it has been already registered.

> Rails.application.config.middleware
=> #<ActionDispatch::MiddlewareStack:0x0000000c18fhw3 @middlewares=[ ... OmniAuth::Builder]>
> Rails.application.config.middleware.use OmniAuth::Builder
RuntimeError: can't modify frozen Array
from /home/vagrant/.rvm/gems/ruby-2.1.2/gems/actionpack-4.0.0/lib/action_dispatch/middleware/stack.rb:112:in `push'
> Rails.application.config.middleware.middlewares.frozen?
=> true

Array is frozen and you can't modify it

@keesbriggs
Copy link

keesbriggs commented Jan 31, 2017

I have the same error.

I moved it to application.rb like so, and it worked: (adapted for your code)

config.middleware.use ::OmniAuth::Builder do
        MyApp::Application::OmniAuth.settings.each do |service, secrets|
          provider service.to_sym, secrets['API_key'], secrets['app_secret']
        end
      end

Just a thought.

@tmilewski
Copy link
Member

☝️ 👍

Re-open if need be.

@atishay5395
Copy link

The error Im getting is:
RuntimeError: can't modify frozen array
insert at org/jruby/RubyArray.java:959
I tried to follow the steps from : https://launchschool.com/blog/facebook-graph-api-using-omniauth-facebook-and-koala
Could anyone help me out with this?

@LucasCioffi
Copy link

I had the same problem in production but found that it goes away when setting config.eager_load = false in production.rb. Is that a surprise or expected?

It's fine for the demo site I'm building, but it comes at a performance cost according to the note in production.rb:

  # Eager load code on boot. This eager loads most of Rails and
  # your application in memory, allowing both threaded web servers
  # and those relying on copy on write to perform better.
  # Rake tasks automatically ignore this option for performance.

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

7 participants