RuntimeError: can't modify frozen Array (Rollbar, Rails 5.1 upgrade)
In most cases, that error is a red herring for something else.
When encountering it, don't get overwhelmed with the recurrent can't modify frozen Array
error messages, and instead check the very first error that appears when running a spec.
For example:
Failure/Error: validate :uniqueness, if: 'should_be_unique?'
ArgumentError: Passing string to be evaluated in :if and :unless
conditional options is not supported. Pass a symbol for an instance
method, or a lambda, proc or block, instead.
Rails test: RuntimeError: can't modify frozen String
I figured it out, turns out it was related to the Algolia tags
section in the model. I upgraded algolia-rails
package to a newer version and also changed:
["site_#{site.id}", status]
to:
["site_#{site.id}", status.dup]
Rails: Frozen Error when trying to run rails application
Finally, I found the reason. I will explain here the way which I found the solution for the issue so that it may help others who encounter the same error.
I saw the FrozenError class documentation and found that this was introduced in ruby 2.5.x and later. This is the document
FrozenError Doc . I just first upgraded ruby version to latest 2.6.x but this didn't solve the issue.
Fix:
- Downgraded the ruby version below 2.5.x to 2.4.x.
- Now in 2.4.x, this FrozenError class does not exist.
- I could now see the real error that caused the issue. It was a
SystemStackError. - It was caused due a gem in project (wicked_pdf).
- Removing the gem solved my issue.
Related Topics
Installing Libyaml for Ruby on a MAC Osx (Lion)
Actioncable - Failed to Upgrade to Websocket in Production
/Usr/Bin/Env Ruby_Noexec_Wrapper Fails with No File or Directory
Check If Array of Integers Increments in Ruby
Many: 'Require': Cannot Load Such File -- "Gem_Name" (Loaderror) After Upgrade of Ruby/Rails
How to Know the Current Rake Task
Ruby 1.9 Doesn't Support Unicode Normalization Yet
How to Remove Blank Values Params from Query String
Rails/Activerecord: Save Changes to a Model's Associated Collections
Ruby on Rails: Search Form - Multiple Search Fields
Multiple Level Nesting in Yaml
Rails 5.0.0 When Installing "Nio4R":Failed to Build Gem Native Extension
Ruby on Rails Map.Root Doesn't Seem to Be Working
Ruby: Is Variable Is Object in Ruby
Ruby Gems Won't Load Even Though Installed
Devise Not Displaying Error Messge During an Authentication Failure