devise icon indicating copy to clipboard operation
devise copied to clipboard

ActiveSupport::MessageEncryptor::InvalidMessage (ActiveSupport::MessageEncryptor::InvalidMessage)

Open ghoshnirmalya opened this issue 8 years ago • 10 comments

Precheck

  • Do not use the issues tracker for help or support, try Stack Overflow.
  • For bugs, do a quick search and make sure the bug has not yet been reported
  • Finally, be nice and have fun!

Environment

  • Ruby [2.5.1]
  • Rails [5.2.0]
  • Devise [4.4.3]

Current behavior

Getting the following error while doing bundle install:

/usr/local/bundle/gems/activesupport-5.2.0/lib/active_support/message_encryptor.rb:206:in `rescue in _decrypt': ActiveSupport::MessageEncryptor::InvalidMessage (ActiveSupport::MessageEncryptor::InvalidMessage)

Include code samples, errors, steps to reproduce the error and stacktraces if appropriate.

Will be even more helpful if you provide a sample application or a test case that reproduces the error.

Expected behavior

ghoshnirmalya avatar Jul 14 '18 15:07 ghoshnirmalya

It 's not a Devise issue, it seems like something in your Rails setup. I could help you if you give a sample application that reproduces this error in isolation.

feliperenan avatar Jul 14 '18 16:07 feliperenan

@feliperenan Thank you for your response.

Here is an example repository: https://github.com/ghoshnirmalya/linkedin-rails

Steps to reproduce the error:

  1. Add the devise gem to Gemfile
  2. Run bundle install
  3. Run rails generate devise:install

The repository is very small consisting of only one model.

ghoshnirmalya avatar Jul 15 '18 07:07 ghoshnirmalya

@ghoshnirmalya do you solved thats issue? i got same issue.

SeptiyanAndika avatar Jul 19 '18 02:07 SeptiyanAndika

@SeptiyanAndika

  1. Remove your credentials.yml.enc file.

  2. bin/rails credentials:edit (If you have EDITOR set in your $PATH) EDITOR="vi --wait" bin/rails credentials:edit (If you don't have EDITOR set in your $PATH)

    This will generate a new credentials.yml.enc.

After that, if you try doing rails g devise:install, it will work.

ghoshnirmalya avatar Jul 19 '18 02:07 ghoshnirmalya

Thanks @ghoshnirmalya , its working for me.

SeptiyanAndika avatar Jul 19 '18 03:07 SeptiyanAndika

Thanks @ghoshnirmalya

TomaszKot11 avatar Feb 10 '19 10:02 TomaszKot11

Thanks @ghoshnirmalya

dhoangk07 avatar May 03 '19 07:05 dhoangk07

In my case I run into an error of:

root@rails-56c75c7bb5-t8tsv:/app# rm config/credentials.yml.enc 
root@rails-56c75c7bb5-t8tsv:/app# bin/rails credentials:edit 
Traceback (most recent call last):
	64: from bin/rails:3:in `<main>'
	63: from bin/rails:3:in `load'
	62: from /app/bin/spring:15:in `<top (required)>'
	61: from /usr/local/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:70:in `require'
	60: from /usr/local/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:70:in `require'
	59: from /usr/local/bundle/gems/spring-2.0.2/lib/spring/binstub.rb:31:in `<top (required)>'
	58: from /usr/local/bundle/gems/spring-2.0.2/lib/spring/binstub.rb:31:in `load'
	57: from /usr/local/bundle/gems/spring-2.0.2/bin/spring:49:in `<top (required)>'
	56: from /usr/local/bundle/gems/spring-2.0.2/lib/spring/client.rb:30:in `run'
	55: from /usr/local/bundle/gems/spring-2.0.2/lib/spring/client/command.rb:7:in `call'
	54: from /usr/local/bundle/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in `call'
	53: from /usr/local/bundle/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in `load'
	52: from /app/bin/rails:9:in `<top (required)>'
	51: from /usr/local/bundle/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:283:in `require'
	50: from /usr/local/bundle/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:249:in `load_dependency'
	49: from /usr/local/bundle/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:283:in `block in require'
	48: from /usr/local/bundle/gems/bootsnap-1.3.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:29:in `require'
	47: from /usr/local/bundle/gems/bootsnap-1.3.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:20:in `require_with_bootsnap_lfi'
	46: from /usr/local/bundle/gems/bootsnap-1.3.1/lib/bootsnap/load_path_cache/loaded_features_index.rb:65:in `register'
	45: from /usr/local/bundle/gems/bootsnap-1.3.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `block in require_with_bootsnap_lfi'
	44: from /usr/local/bundle/gems/bootsnap-1.3.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require'
	43: from /usr/local/bundle/gems/railties-5.2.0/lib/rails/commands.rb:18:in `<main>'
	42: from /usr/local/bundle/gems/railties-5.2.0/lib/rails/command.rb:46:in `invoke'
	41: from /usr/local/bundle/gems/railties-5.2.0/lib/rails/command/base.rb:65:in `perform'
	40: from /usr/local/bundle/gems/thor-0.20.0/lib/thor.rb:387:in `dispatch'
	39: from /usr/local/bundle/gems/thor-0.20.0/lib/thor/invocation.rb:126:in `invoke_command'
	38: from /usr/local/bundle/gems/thor-0.20.0/lib/thor/command.rb:27:in `run'
	37: from /usr/local/bundle/gems/railties-5.2.0/lib/rails/commands/credentials/credentials_command.rb:20:in `edit'
	36: from /usr/local/bundle/gems/railties-5.2.0/lib/rails/command/actions.rb:18:in `require_application_and_environment!'
	35: from /usr/local/bundle/gems/railties-5.2.0/lib/rails/application.rb:337:in `require_environment!'
	34: from /usr/local/bundle/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:283:in `require'
	33: from /usr/local/bundle/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:249:in `load_dependency'
	32: from /usr/local/bundle/gems/activesupport-5.2.0/lib/active_support/dependencies.rb:283:in `block in require'
	31: from /usr/local/bundle/gems/bootsnap-1.3.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:29:in `require'
	30: from /usr/local/bundle/gems/bootsnap-1.3.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:20:in `require_with_bootsnap_lfi'
	29: from /usr/local/bundle/gems/bootsnap-1.3.1/lib/bootsnap/load_path_cache/loaded_features_index.rb:65:in `register'
	28: from /usr/local/bundle/gems/bootsnap-1.3.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `block in require_with_bootsnap_lfi'
	27: from /usr/local/bundle/gems/bootsnap-1.3.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require'
	26: from /app/config/environment.rb:5:in `<main>'
	25: from /usr/local/bundle/gems/railties-5.2.0/lib/rails/application.rb:361:in `initialize!'
	24: from /usr/local/bundle/gems/railties-5.2.0/lib/rails/initializable.rb:60:in `run_initializers'
	23: from /usr/local/lib/ruby/2.5.0/tsort.rb:205:in `tsort_each'
	22: from /usr/local/lib/ruby/2.5.0/tsort.rb:226:in `tsort_each'
	21: from /usr/local/lib/ruby/2.5.0/tsort.rb:347:in `each_strongly_connected_component'
	20: from /usr/local/lib/ruby/2.5.0/tsort.rb:347:in `call'
	19: from /usr/local/lib/ruby/2.5.0/tsort.rb:347:in `each'
	18: from /usr/local/lib/ruby/2.5.0/tsort.rb:349:in `block in each_strongly_connected_component'
	17: from /usr/local/lib/ruby/2.5.0/tsort.rb:431:in `each_strongly_connected_component_from'
	16: from /usr/local/lib/ruby/2.5.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
	15: from /usr/local/lib/ruby/2.5.0/tsort.rb:228:in `block in tsort_each'
	14: from /usr/local/bundle/gems/railties-5.2.0/lib/rails/initializable.rb:61:in `block in run_initializers'
	13: from /usr/local/bundle/gems/railties-5.2.0/lib/rails/initializable.rb:32:in `run'
	12: from /usr/local/bundle/gems/railties-5.2.0/lib/rails/initializable.rb:32:in `instance_exec'
	11: from /usr/local/bundle/gems/railties-5.2.0/lib/rails/application/finisher.rb:75:in `block in <module:Finisher>'
	10: from /usr/local/bundle/gems/activesupport-5.2.0/lib/active_support/lazy_load_hooks.rb:51:in `run_load_hooks'
	 9: from /usr/local/bundle/gems/activesupport-5.2.0/lib/active_support/lazy_load_hooks.rb:51:in `each'
	 8: from /usr/local/bundle/gems/activesupport-5.2.0/lib/active_support/lazy_load_hooks.rb:52:in `block in run_load_hooks'
	 7: from /usr/local/bundle/gems/activesupport-5.2.0/lib/active_support/lazy_load_hooks.rb:67:in `execute_hook'
	 6: from /usr/local/bundle/gems/activesupport-5.2.0/lib/active_support/lazy_load_hooks.rb:62:in `with_execution_control'
	 5: from /usr/local/bundle/gems/activesupport-5.2.0/lib/active_support/lazy_load_hooks.rb:69:in `block in execute_hook'
	 4: from /usr/local/bundle/gems/activestorage-5.2.0/lib/active_storage/engine.rb:67:in `block (2 levels) in <class:Engine>'
	 3: from /usr/local/bundle/gems/railties-5.2.0/lib/rails/application.rb:205:in `message_verifier'
	 2: from /usr/local/bundle/gems/railties-5.2.0/lib/rails/application.rb:176:in `key_generator'
	 1: from /usr/local/bundle/gems/railties-5.2.0/lib/rails/application.rb:432:in `secret_key_base'
/usr/local/bundle/gems/railties-5.2.0/lib/rails/application.rb:585:in `validate_secret_key_base': Missing `secret_key_base` for 'production' environment, set this string with `rails credentials:edit` (ArgumentError)

chrissound avatar Oct 05 '19 18:10 chrissound

This is my case, I got stacked with this on my git, but on my rails its no failure on test. rspec

Zhi0105 avatar Feb 25 '22 19:02 Zhi0105

It can solve (ActiveSupport::MessageEncryptor::InvalidMessage) issue using the following steps:

  • [x] Delete your master.key and credentials.yml.enc
  • [x] Terminal use this command: rails credentials:edit
  • [x] Run this command: rails g devise:install

This should solve the error.

rray524 avatar Nov 06 '24 13:11 rray524