in `decode64': undefined method `unpack1' for nil:NilClass (NoMethodError)
Asked Answered
O

3

10

After deploying a new rails app to Heroku I'm getting a NoMethodError. Everything works fine locally. I'm unsure how to and where to add the method.

I'm new to ruby (coding in general) and it seems to be in the ruby-config and not this specific app, but I didn't have any problems with deploying other apps to Heroku so I wonder how the config could have changed.

I've added Postgres and Redis to Heroku and am using ruby 2.6.3 and Rails 6.0.0.rc1

Error message:

/app/vendor/ruby-2.6.3/lib/ruby/2.6.0/base64.rb:59:in `decode64': undefined method `unpack1' for nil:NilClass (NoMethodError)
2019-07-25T08:43:02.237469+00:00 app[web.1]: from /app/app/models/user/connected_account.rb:37:in `<class:ConnectedAccount>'
2019-07-25T08:43:02.237508+00:00 app[web.1]: from /app/app/models/user/connected_account.rb:31:in `<main>'
2019-07-25T08:43:02.237532+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
2019-07-25T08:43:02.237554+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
2019-07-25T08:43:02.237576+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
2019-07-25T08:43:02.237614+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
2019-07-25T08:43:02.237651+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
2019-07-25T08:43:02.237674+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/zeitwerk-2.1.6/lib/zeitwerk/kernel.rb:16:in `require'
2019-07-25T08:43:02.237696+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.0.rc1/lib/active_support/dependencies.rb:302:in `block in require'
2019-07-25T08:43:02.237720+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.0.rc1/lib/active_support/dependencies.rb:268:in `load_dependency'
Olshausen answered 25/7, 2019 at 8:37 Comment(1)
Please post a full stack trace.Progenitive
C
6

You are likely missing the RAILS_MASTER_KEY in your environment.

From your stack trace, the error is generated at /app/app/models/user/connected_account.rb:37:

  attr_encrypted :access_token, key: Base64.decode64(Rails.application.credentials.access_token_encryption_key)

For your production environment, you'll find the key by running:

cat config/credentials/production.key
Counterplot answered 8/5, 2020 at 13:48 Comment(1)
Yes indeed. It worked by setting heroku config:set RAILS_MASTER_KEY=<your-master-key>Olshausen
V
10

The error happens if you call Base64.decode64(nil). The method however is strictly expecting a String object here.

You are likely calling the method with some variable that is usually supposed to be a String but is currently nil for some reason. Check your full stack trace and the related data to fix passed data to be a String.

Velarize answered 25/7, 2019 at 9:2 Comment(0)
C
6

You are likely missing the RAILS_MASTER_KEY in your environment.

From your stack trace, the error is generated at /app/app/models/user/connected_account.rb:37:

  attr_encrypted :access_token, key: Base64.decode64(Rails.application.credentials.access_token_encryption_key)

For your production environment, you'll find the key by running:

cat config/credentials/production.key
Counterplot answered 8/5, 2020 at 13:48 Comment(1)
Yes indeed. It worked by setting heroku config:set RAILS_MASTER_KEY=<your-master-key>Olshausen
Q
1

I did a global search in my repository for Base64.decode64(.

Saw that it was only called in one place, with an environment variable, that I hadn't added into my .env file.

Once I added the environment variable all was good to go.

Quintanilla answered 5/6 at 11:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.