LoadError: cannot load such file -- sassc - sprockets

running rake assets:precompile ends with the error.
Can't find why it still requires sassc, sassc only was in project when migrated to sprockets 4 using Guide to upgrading from Sprockets 3.x to 4.x:
gem 'sass-rails', '>= 5'
bundle update sass-rails sprockets
and then followed dartsass-rails install documentation.
did:
rails tmp:clear
rake assets:clobber
rake assets:precompile
ruby-3.1.2
gem 'rails', '7.0.3.1'
gem 'webrick'
gem 'sprockets-rails', '~> 3.4', '>= 3.4.2'
gem 'dartsass-rails', '~> 0.4.0'
...
manifest.js file content:
//= link_tree ../images
//= link application.css
//= link application.js
//
//= link_tree ../builds
error log:
** Invoke assets:precompile (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke environment (first_time)
** Execute environment
** Invoke dartsass:build (first_time)
** Invoke environment
** Execute dartsass:build
+ /.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/dartsass-rails-0.4.0/exe/darwin/sass --style\=compressed --no-source-map --load-path
/app/assets/stylesheets --load-path
/app/assets/builds --load-path
/app/assets/config --load-path
/app/assets/fonts --load-path
/app/assets/images --load-path
/app/assets/javascripts --load-path
/app/assets/stylesheets --load-path
/lib/assets/javascripts --load-path
/lib/assets/stylesheets --load-path
/vendor/assets/javascripts --load-path
/vendor/assets/stylesheets --load-path
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/bundler/gems/flex_calendar-aae0ac1c9b3f/app/assets/javascripts --load-path
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/bundler/gems/flex_calendar-aae0ac1c9b3f/app/assets/images --load-path
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/bundler/gems/flex_calendar-aae0ac1c9b3f/app/assets/stylesheets --load-path
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/bundler/gems/flex_calendar-aae0ac1c9b3f/lib/assets/javascripts --load-path
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/flatpickr-4.5.7.0/vendor/assets/javascripts --load-path
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/bundler/gems/flex_calendar-aae0ac1c9b3f/vendor/assets/javascripts --load-path
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/flatpickr-4.5.7.0/vendor/assets/stylesheets --load-path
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/tinymce-rails-5.10.5/app/assets/javascripts --load-path
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/tinymce-rails-5.10.5/app/assets/source --load-path
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/tinymce-rails-5.10.5/vendor/assets/config --load-path
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/jquery-minicolors-rails-2.2.6.2/vendor/assets/javascripts --load-path
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/tinymce-rails-5.10.5/vendor/assets/javascripts --load-path
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/jquery-minicolors-rails-2.2.6.2/vendor/assets/stylesheets --load-path
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/select2-rails-4.0.13/vendor/assets/javascripts --load-path
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/select2-rails-4.0.13/vendor/assets/stylesheets --load-path
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/jquery-ui-rails-5.0.5/app/assets/images --load-path
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/jquery-ui-rails-5.0.5/app/assets/javascripts --load-path
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/jquery-ui-rails-5.0.5/app/assets/stylesheets --load-path
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/jquery-rails-4.2.1/vendor/assets/javascripts --load-path
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/coffee-rails-5.0.0/lib/assets/javascripts --load-path
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/actiontext-7.0.3.1/app/assets/javascripts --load-path
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/actiontext-7.0.3.1/app/assets/stylesheets --load-path
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/actioncable-7.0.3.1/app/assets/javascripts --load-path
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/activestorage-7.0.3.1/app/assets/javascripts --load-path
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/actionview-7.0.3.1/lib/assets/compiled --load-path
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/react-rails-1.9.0/lib/assets/react-source/development --load-path
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/react-rails-1.9.0/lib/assets/javascripts/ --load-path
/app/assets/fonts
/app/assets/stylesheets/application.scss:
/app/assets/builds/application.css
** Execute assets:precompile
rake aborted!
LoadError: cannot load such file -- sassc
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/zeitwerk-2.6.0/lib/zeitwerk/kernel.rb:35:in `require'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/zeitwerk-2.6.0/lib/zeitwerk/kernel.rb:35:in `require'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/autoload/sassc.rb:2:in `<top (required)>'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/zeitwerk-2.6.0/lib/zeitwerk/kernel.rb:35:in `require'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/zeitwerk-2.6.0/lib/zeitwerk/kernel.rb:35:in `require'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/sassc_processor.rb:42:in `initialize'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/sassc_processor.rb:27:in `new'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/sassc_processor.rb:27:in `instance'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/sassc_processor.rb:31:in `call'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/processor_utils.rb:84:in `call_processor'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/processor_utils.rb:66:in `block in call_processors'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/processor_utils.rb:65:in `reverse_each'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/processor_utils.rb:65:in `call_processors'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/processor_utils.rb:22:in `block in <class:CompositeProcessor>'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/processor_utils.rb:33:in `call'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/processor_utils.rb:84:in `call_processor'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/processor_utils.rb:66:in `block in call_processors'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/processor_utils.rb:65:in `reverse_each'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/processor_utils.rb:65:in `call_processors'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/loader.rb:182:in `load_from_unloaded'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/loader.rb:59:in `block in load'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/loader.rb:337:in `fetch_asset_from_dependency_cache'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/loader.rb:43:in `load'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/cached_environment.rb:44:in `block in load'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/cached_environment.rb:44:in `fetch'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/cached_environment.rb:44:in `load'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/bundle.rb:27:in `call'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/processor_utils.rb:84:in `call_processor'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/processor_utils.rb:66:in `block in call_processors'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/processor_utils.rb:65:in `reverse_each'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/processor_utils.rb:65:in `call_processors'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/loader.rb:182:in `load_from_unloaded'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/loader.rb:59:in `block in load'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/loader.rb:337:in `fetch_asset_from_dependency_cache'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/loader.rb:43:in `load'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/cached_environment.rb:44:in `block in load'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/cached_environment.rb:44:in `fetch'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/cached_environment.rb:44:in `load'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/base.rb:81:in `find_asset'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/base.rb:88:in `find_all_linked_assets'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/manifest.rb:125:in `each'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/manifest.rb:125:in `to_a'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/sprockets-4.1.1/lib/sprockets/manifest.rb:125:in `block (2 levels) in find'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/executor/safe_task_executor.rb:24:in `block in execute'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/synchronization/mutex_lockable_object.rb:47:in `block in synchronize'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/synchronization/mutex_lockable_object.rb:47:in `synchronize'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/synchronization/mutex_lockable_object.rb:47:in `synchronize'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/executor/safe_task_executor.rb:22:in `execute'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/promise.rb:564:in `block in realize'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:352:in `run_task'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:343:in `block (3 levels) in create_worker'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:334:in `loop'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:334:in `block (2 levels) in create_worker'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:333:in `catch'
/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/concurrent-ruby-1.1.10/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:333:in `block in create_worker'
Tasks: TOP => assets:precompile
OS: mac
When I install gem with dependency on sassc-rails (example pdfjs_viewer-rails) and start server with ./bin/dev , then web starts up and works fine.
Question:
Any idea what could be reason of this and what would be possible solution?

Found out the problem:
As under stylesheets root folder were extra example.scss file and it was set to precompile with:
Rails.application.config.assets.precompile += %w( example.css )
This errors showed because file actually had different extension.
Solution:
Took out example.css from precompilation;
Added file for dartsass to handle it using:
Rails.application.config.dartsass.builds = {
"application.scss" => "application.css",
"example.scss" => "example.css"
}

I fixed it by running rails tmp:clear and restarting the server; I did not include any file in my assets.rb file, also this started happening to me when I ran:
$ rails importmap:install
$ rails turbo:install stimulus:install

I have run across this issue as well. Came accross this thread by searching for cannot load such file -- sass.
I know that you are using sprockes, but I got this error with webpacker.
In webpacker, the default configuration is not to extract scss in the development environment.
You need to turn this on in config/webpacker.yml.
development:
<<: *default
compile: true
extract_css: true
I don't know why this is happening with sprockets, but someone else may have the same issue I was having, and hopefully it helps them.

Related

Rails - PG:InvalidSchemaName

When running rake db:migrate using postgres I get the following error:
rake aborted!
ActiveRecord::StatementInvalid: PG::InvalidSchemaName: ERROR: no
schema has been selected to create in
LINE 1: CREATE TABLE "schema_migrations" ("version" character
varyin...
^
: CREATE TABLE "schema_migrations" ("version" character varying NOT
NULL)
/home/garrett/.rvm/gems/ruby-2.5.0/gems/activerecord-4.2.8/lib/active_record/connection_adapters/postgresql/database_statements.rb:155:in `async_exec'
/home/garrett/.rvm/gems/ruby-2.5.0/gems/activerecord-4.2.8/lib/active_record/connection_adapters/postgresql/database_statements.rb:155:in `block in execute'
/home/garrett/.rvm/gems/ruby-2.5.0/gems/activerecord-4.2.8/lib/active_record/connection_adapters/abstract_adapter.rb:484:in `block in log'
/home/garrett/.rvm/gems/ruby-2.5.0/gems/activesupport-4.2.8/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/home/garrett/.rvm/gems/ruby-2.5.0/gems/activerecord-4.2.8/lib/active_record/connection_adapters/abstract_adapter.rb:478:in `log'
/home/garrett/.rvm/gems/ruby-2.5.0/gems/activerecord-4.2.8/lib/active_record/connection_adapters/postgresql/database_statements.rb:154:in `execute'
/home/garrett/.rvm/gems/ruby-2.5.0/gems/activerecord-4.2.8/lib/active_record/connection_adapters/abstract/schema_statements.rb:222:in `create_table'
/home/garrett/.rvm/gems/ruby-2.5.0/gems/activerecord-4.2.8/lib/active_record/schema_migration.rb:29:in `create_table'
/home/garrett/.rvm/gems/ruby-2.5.0/gems/activerecord-4.2.8/lib/active_record/connection_adapters/abstract/schema_statements.rb:836:in `initialize_schema_migrations_table'
/home/garrett/.rvm/gems/ruby-2.5.0/gems/activerecord-4.2.8/lib/active_record/migration.rb:925:in `initialize'
/home/garrett/.rvm/gems/ruby-2.5.0/gems/activerecord-4.2.8/lib/active_record/migration.rb:823:in `new'
/home/garrett/.rvm/gems/ruby-2.5.0/gems/activerecord-4.2.8/lib/active_record/migration.rb:823:in `up'
/home/garrett/.rvm/gems/ruby-2.5.0/gems/activerecord-4.2.8/lib/active_record/migration.rb:801:in `migrate'
/home/garrett/.rvm/gems/ruby-2.5.0/gems/activerecord-4.2.8/lib/active_record/tasks/database_tasks.rb:137:in `migrate'
/home/garrett/.rvm/gems/ruby-2.5.0/gems/activerecord-4.2.8/lib/active_record/railties/databases.rake:44:in `block (2 levels) in <top (required)>'
/home/garrett/.rvm/gems/ruby-2.5.0#global/gems/rake-12.3.0/exe/rake:27:in `<top (required)>'
/home/garrett/.rvm/gems/ruby-2.5.0/bin/ruby_executable_hooks:15:in `eval'
/home/garrett/.rvm/gems/ruby-2.5.0/bin/ruby_executable_hooks:15:in `<main>'
I have already tried granting usage to the public schema, but i still encounter the error.
I used the following:
ALTER SCHEMA public OWNER to postgres;
grant usage on schema public to public;
grant create on schema public to public;

Determine which callback invoked throw(:abort) in Rails 5

Given a Model in which a callback invoked throw(:abort), how can one determine which callback did the deed without modifying the callbacks themselves?
For example, the following Model...
class OddDuck < ApplicationRecord
before_save :random_abort_1
before_save :random_abort_2
private
def random_abort_1
if Random.rand(2) == 1
throw(:abort)
end
end
def random_abort_2
if Random.rand(2) == 1
throw(:abort)
end
end
end
... will sometimes fail to save ...
$ rails c
Running via Spring preloader in process 81303
Loading development environment (Rails 5.0.0.1)
irb(main):001:0> OddDuck.create!
(0.1ms) begin transaction
(0.1ms) rollback transaction
ActiveRecord::RecordNotSaved: Failed to save the record
from /Users/alice/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-5.0.0.1/lib/active_record/persistence.rb:152:in `save!'
from /Users/alice/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-5.0.0.1/lib/active_record/validations.rb:50:in `save!'
from /Users/alice/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-5.0.0.1/lib/active_record/attribute_methods/dirty.rb:30:in `save!'
from /Users/alice/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-5.0.0.1/lib/active_record/transactions.rb:324:in `block in save!'
from /Users/alice/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-5.0.0.1/lib/active_record/transactions.rb:395:in `block in with_transaction_returning_status'
from /Users/alice/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract/database_statements.rb:232:in `block in transaction'
from /Users/alice/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract/transaction.rb:189:in `within_new_transaction'
from /Users/alice/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract/database_statements.rb:232:in `transaction'
from /Users/alice/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-5.0.0.1/lib/active_record/transactions.rb:211:in `transaction'
from /Users/alice/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-5.0.0.1/lib/active_record/transactions.rb:392:in `with_transaction_returning_status'
from /Users/alice/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-5.0.0.1/lib/active_record/transactions.rb:324:in `save!'
from /Users/alice/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-5.0.0.1/lib/active_record/suppressor.rb:45:in `save!'
from /Users/alice/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-5.0.0.1/lib/active_record/persistence.rb:51:in `create!'
from (irb):1
from /Users/alice/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.0.1/lib/rails/commands/console.rb:65:in `start'
from /Users/alice/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.0.1/lib/rails/commands/console_helper.rb:9:in `start'
from /Users/alice/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:78:in `console'
from /Users/alice/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:49:in `run_command!'
from /Users/alice/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-5.0.0.1/lib/rails/commands.rb:18:in `<top (required)>'
from /Users/alice/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `require'
from /Users/alice/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `block in require'
from /Users/alice/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:259:in `load_dependency'
from /Users/alice/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `require'
from /Users/alice/Desktop/site/bin/rails:9:in `<top (required)>'
from /Users/alice/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:287:in `load'
from /Users/alice/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:287:in `block in load'
from /Users/alice/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:259:in `load_dependency'
from /Users/alice/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:287:in `load'
from /Users/alice/.rbenv/versions/2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/alice/.rbenv/versions/2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from -e:1:in `<main>'
... but it is not readily apparent from the backtrace which callback caused the abort.
throw also accepts an optional return value, so you can use that if you need to know the callback that triggered the throw.
throw(tag [, obj])
Transfers control to the end of the active catch block waiting for tag. Raises UncaughtThrowError if there is no catch block for the tag. The optional second parameter supplies a return value for the catch block, which otherwise defaults to nil.
https://ruby-doc.org/core-2.4.1/Kernel.html#method-i-throw
For example:
def random_abort_1
if Random.rand(2) == 1
throw(:abort, __method__)
end
end
Will return random_abort_1.

I want to use HTTPS connection on my GIT repo and the crendentials are in data bags

I am trying to create a recipe that will download my git repo using my user name and password which are inside a databag. This is my code and beneath is an error that says it can't get my credentials in my git block. Any ideas?
accounts = data_bag_item('databag_name', 'databag_item')
git "my_repo" do
user accounts
puts user.inspect
repository "https://github.com/my_repo/myrepo.git"
reference "branch"
destination "/var/www/myrepo"
action :sync
end
My error was :
Expected process to exit with [0], but received '1'
---- Begin output of git ls-remote https://github.com/my_repo/myrepo.git branch ----
STDOUT: 
STDERR: /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/mixlib-shellout-1.1.0/lib/mixlib/shellout.rb:172:in `getpwnam': can't find user for accounts (ArgumentError)
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/mixlib-shellout-1.1.0/lib/mixlib/shellout.rb:172:in `uid'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/mixlib-shellout-1.1.0/lib/mixlib/shellout/unix.rb:92:in `set_user'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/mixlib-shellout-1.1.0/lib/mixlib/shellout/unix.rb:226:in `block in fork_subprocess'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/mixlib-shellout-1.1.0/lib/mixlib/shellout/unix.rb:222:in `fork'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/mixlib-shellout-1.1.0/lib/mixlib/shellout/unix.rb:222:in `fork_subprocess'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/mixlib-shellout-1.1.0/lib/mixlib/shellout/unix.rb:35:in `run_command'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/mixlib-shellout-1.1.0/lib/mixlib/shellout.rb:222:in `run_command'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/mixin/shell_out.rb:30:in `shell_out'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/mixin/shell_out.rb:35:in `shell_out!'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/provider/git.rb:222:in `remote_resolve_reference'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/provider/git.rb:212:in `target_revision'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/provider/git.rb:68:in `block (2 levels) in define_resource_requirements'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/mixin/why_run.rb:232:in `call'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/mixin/why_run.rb:232:in `run'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/mixin/why_run.rb:322:in `block in run'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/mixin/why_run.rb:321:in `each'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/mixin/why_run.rb:321:in `run'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/provider.rb:128:in `process_resource_requirements'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/provider.rb:105:in `run_action'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/resource.rb:597:in `run_action'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/runner.rb:49:in `run_action'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/runner.rb:81:in `block (2 levels) in converge'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/runner.rb:81:in `each'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/runner.rb:81:in `block in converge'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/resource_collection.rb:94:in `block in execute_each_resource'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/resource_collection/stepable_iterator.rb:116:in `call'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/resource_collection/stepable_iterator.rb:116:in `call_iterator_block'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/resource_collection/stepable_iterator.rb:85:in `step'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/resource_collection/stepable_iterator.rb:104:in `iterate'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/resource_collection/stepable_iterator.rb:55:in `each_with_index'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/resource_collection.rb:92:in `execute_each_resource'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/runner.rb:80:in `converge'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/client.rb:378:in `converge'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/client.rb:420:in `do_run'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/client.rb:176:in `run'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/application.rb:140:in `run_chef_client'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/application/client.rb:274:in `block in run_application'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/application/client.rb:267:in `loop'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/application/client.rb:267:in `run_application'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/application.rb:72:in `run'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/bin/chef-client:26:in `<top (required)>'
from /usr/bin/chef-client:23:in `load'
from /usr/bin/chef-client:23:in `<main>'
---- End output of git ls-remote https://github.com/my_repo/myrepo.git branch ----
Ran git ls-remote https://github.com/my_repo/myrepo.git branch returned 1
Resource Declaration:
---------------------
# In /var/chef/cache/cookbooks/themes/recipes/default.rb
 34: git "my_repo" do
 35:   user "accounts"
 36:   puts user.inspect
 37:   repository "https://github.com/my_repo/myrepo.git"
 38:   reference "branch"
 39:   destination "/var/www/my_repo"
 41:   action :sync
 42: end
 43: 
Compiled Resource:
------------------
# Declared in /var/chef/cache/cookbooks/themes/recipes/default.rb:34:in `from_file'
git("my_repo") do
  provider Chef::Provider::Git
  action [:sync]
  retries 0
  retry_delay 2
  destination "/var/www/my_repo"
  revision "branch"
  remote "origin"
  cookbook_name "themes"
  recipe_name "default"
  user "accounts"
  repository "https://github.com/my_repo/myrepo.git"
end
[2013-01-31T10:12:21+00:00] ERROR: Running exception handlers
[2013-01-31T10:12:21+00:00] FATAL: Saving node information to /var/chef/cache/failed-run-data.json
[2013-01-31T10:12:21+00:00] ERROR: Exception handlers complete
[2013-01-31T10:12:21+00:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
[2013-01-31T10:12:21+00:00] FATAL: Mixlib::ShellOut::ShellCommandFailed: git[my_repo] (themes::default line 34) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '1'
---- Begin output of git ls-remote https://github.com/my_repo/myrepo.git branch ----
STDOUT: 
STDERR: /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/mixlib-shellout-1.1.0/lib/mixlib/shellout.rb:172:in `getpwnam': can't find user for accounts (ArgumentError)
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/mixlib-shellout-1.1.0/lib/mixlib/shellout.rb:172:in `uid'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/mixlib-shellout-1.1.0/lib/mixlib/shellout/unix.rb:92:in `set_user'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/mixlib-shellout-1.1.0/lib/mixlib/shellout/unix.rb:226:in `block in fork_subprocess'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/mixlib-shellout-1.1.0/lib/mixlib/shellout/unix.rb:222:in `fork'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/mixlib-shellout-1.1.0/lib/mixlib/shellout/unix.rb:222:in `fork_subprocess'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/mixlib-shellout-1.1.0/lib/mixlib/shellout/unix.rb:35:in `run_command'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/mixlib-shellout-1.1.0/lib/mixlib/shellout.rb:222:in `run_command'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/mixin/shell_out.rb:30:in `shell_out'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/mixin/shell_out.rb:35:in `shell_out!'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/provider/git.rb:222:in `remote_resolve_reference'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/provider/git.rb:212:in `target_revision'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/provider/git.rb:68:in `block (2 levels) in define_resource_requirements'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/mixin/why_run.rb:232:in `call'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/mixin/why_run.rb:232:in `run'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/mixin/why_run.rb:322:in `block in run'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/mixin/why_run.rb:321:in `each'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/mixin/why_run.rb:321:in `run'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/provider.rb:128:in `process_resource_requirements'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/provider.rb:105:in `run_action'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/resource.rb:597:in `run_action'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/runner.rb:49:in `run_action'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/runner.rb:81:in `block (2 levels) in converge'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/runner.rb:81:in `each'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/runner.rb:81:in `block in converge'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/resource_collection.rb:94:in `block in execute_each_resource'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/resource_collection/stepable_iterator.rb:116:in `call'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/resource_collection/stepable_iterator.rb:116:in `call_iterator_block'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/resource_collection/stepable_iterator.rb:85:in `step'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/resource_collection/stepable_iterator.rb:104:in `iterate'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/resource_collection/stepable_iterator.rb:55:in `each_with_index'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/resource_collection.rb:92:in `execute_each_resource'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/runner.rb:80:in `converge'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/client.rb:378:in `converge'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/client.rb:420:in `do_run'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/client.rb:176:in `run'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/application.rb:140:in `run_chef_client'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/application/client.rb:274:in `block in run_application'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/application/client.rb:267:in `loop'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/application/client.rb:267:in `run_application'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/lib/chef/application.rb:72:in `run'
from /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.18.2/bin/chef-client:26:in `<top (required)>'
from /usr/bin/chef-client:23:in `load'
from /usr/bin/chef-client:23:in `<main>'
---- End output of git ls-remote https://github.com/my_repo/myrepo.git branch ----
Ran git ls-remote https://github.com/my_repo/myrepo.git branch returned 1
---
Is there a sample code that shows how I can download my code from github with authentication via databags.
The user attribute in the git resource is not the username on GitHub, but a system user that will be the owner of the directory where you clone the repository. Obviously you don't have the system user accounts created, so that's why you get the error.
Your git resource should look like this:
git "/var/www/myrepo" do
repository "git#github.com:username/myrepo.git" #or "https://github.com/my_repo/myrepo.git"
revision "HEAD"
action :sync
end
But you need some mechanism to authenticate on GitHub. I propose using ssh-keys, because I don't know any way to store your password for authentication for good - only some caching for small amount of time is available. You can generate a key pair according to this guide on GitHub. You can then save your private key in an encrypted data bag.
{
"id": "mykeys",
"private": "[The private key with newlines replaced with \n]",
"public": "[The public key with newlines replaced with \n]"
}
Then you can use your data bag in the recipe to recreate a private key file in ~/.ssh/id_rsa
keys = Chef::EncryptedDataBagItem.load('databag_name', 'mykeys')
directory ::File.join( ENV['HOME'], '.ssh' ) do
mode 0755
end
file ::File.join( ENV['HOME'], '.ssh', 'id_rsa' ) do
content keys['private']
mode 0600
end
To skip checking authenticity of host 'github.com' create a file in your cookbook files/default/config with the following contents.
Host github.com
StrictHostKeyChecking no
UserKnownHostsFile /dev/null
And add the folowing to the recipe:
cookbook_file ::File.join( ENV['HOME'], '.ssh', 'config' ) do
mode 0644
end
If you want to clone the repository not as root, but as some other user then you have to create all the .ssh configuration files in that user's home directory.

delete a facebook feed post using fb_graph gem

I am using fb_graph rails gem for posting a message to my user's Facebook feed.
I have requested the following permissions:
:scope => 'email, publish_actions, offline_access, publish_stream'
I am able to post to the user's feed. But I am unable to destroy it.
When I execute the following in the Rails Console you can see the errors:
me = FbGraph::User.me( user.access_token )
#facebookpost = me.feed!( :message => "sample feed message", :description => 'sample message')
post = me.feed.find(#facebookpost.identifier).first
post.destroy # this generates the following error
FbGraph::InvalidRequest: OAuthException :: (#100) Invalid parameter
from /home/invinc/.rvm/gems/ruby-1.9.2-p318/gems/fb_graph-2.4.12/lib/fb_graph/exception.rb:47:in `block in handle_httpclient_error'
from /home/invinc/.rvm/gems/ruby-1.9.2-p318/gems/fb_graph-2.4.12/lib/fb_graph/exception.rb:44:in `each'
from /home/invinc/.rvm/gems/ruby-1.9.2-p318/gems/fb_graph-2.4.12/lib/fb_graph/exception.rb:44:in `handle_httpclient_error'
from /home/invinc/.rvm/gems/ruby-1.9.2-p318/gems/fb_graph-2.4.12/lib/fb_graph/node.rb:146:in `handle_response'
from /home/invinc/.rvm/gems/ruby-1.9.2-p318/gems/fb_graph-2.4.12/lib/fb_graph/node.rb:63:in `delete'
from /home/invinc/.rvm/gems/ruby-1.9.2-p318/gems/fb_graph-2.4.12/lib/fb_graph/node.rb:43:in `destroy'
from (irb):67
from /home/invinc/.rvm/gems/ruby-1.9.2-p318/gems/railties-3.1.3/lib/rails/commands/console.rb:45:in `start'
from /home/invinc/.rvm/gems/ruby-1.9.2-p318/gems/railties-3.1.3/lib/rails/commands/console.rb:8:in `start'
from /home/invinc/.rvm/gems/ruby-1.9.2-p318/gems/railties-3.1.3/lib/rails/commands.rb:40:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
1.9.2-p318 :068 > post.destroy(user.access_token)
TypeError: can't convert Symbol into String
from /home/invinc/.rvm/gems/ruby-1.9.2-p318/gems/fb_graph-2.4.12/lib/fb_graph/node.rb:93:in `delete'
from /home/invinc/.rvm/gems/ruby-1.9.2-p318/gems/fb_graph-2.4.12/lib/fb_graph/node.rb:93:in `build_endpoint'
from /home/invinc/.rvm/gems/ruby-1.9.2-p318/gems/fb_graph-2.4.12/lib/fb_graph/node.rb:61:in `delete'
from /home/invinc/.rvm/gems/ruby-1.9.2-p318/gems/fb_graph-2.4.12/lib/fb_graph/node.rb:43:in `destroy'
from (irb):68
from /home/invinc/.rvm/gems/ruby-1.9.2-p318/gems/railties-3.1.3/lib/rails/commands/console.rb:45:in `start'
from /home/invinc/.rvm/gems/ruby-1.9.2-p318/gems/railties-3.1.3/lib/rails/commands/console.rb:8:in `start'
from /home/invinc/.rvm/gems/ruby-1.9.2-p318/gems/railties-3.1.3/lib/rails/commands.rb:40:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
Did I miss any permissions? What can I do to resolve this problem?
You can delete posts with
FbGraph::Post.new(fb_post_id).destroy(access_token: "access_token")
Not the best API though...
The v2.4 requires that you combine the fb_post_id with the client id.
FbGraph2::Post.new("#{client_id}_#{fb_post_id}", access_token: "access_token").destroy

Mongo::OperationFailure, Database command 'filemd5' failed: (errmsg: 'exception: best guess plan requested, but scan and order required)

I have an application that in uploading files to GridFS via MongoMapper/Joint in Padrino. Everything was working fine, and then all of a sudden, I'm getting the error:
Mongo::OperationFailure at /admin/wallpapers/create
Database command 'filemd5' failed: (errmsg: 'exception: best guess plan requested, but scan and order required: query: { files_id: ObjectId('4eaf4abf9972772c94000003') } order: { files_id: 1, n: 1 } choices: { $natural: 1 } '; code: '13284'; ok: '0.0').
The stack trace:
Mongo::OperationFailure - Database command 'filemd5' failed: (errmsg: 'exception: best guess plan requested, but scan and order required: query: { files_id: ObjectId('4eaf4c719972772c9400000b') } order: { files_id: 1, n: 1 } choices: { $natural: 1 } '; code: '13284'; ok: '0.0').:
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/mongo-1.4.1/lib/mongo/db.rb:520:in `command'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/mongo-1.4.1/lib/mongo/gridfs/grid_io.rb:463:in `get_md5'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/mongo-1.4.1/lib/mongo/gridfs/grid_io.rb:453:in `to_mongo_object'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/mongo-1.4.1/lib/mongo/gridfs/grid_io.rb:238:in `close'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/mongo-1.4.1/lib/mongo/gridfs/grid.rb:73:in `put'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/joint-0.6.0/lib/joint/instance_methods.rb:22:in `block in save_attachments'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/joint-0.6.0/lib/joint/instance_methods.rb:18:in `each_pair'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/joint-0.6.0/lib/joint/instance_methods.rb:18:in `save_attachments'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/activesupport-3.0.10/lib/active_support/callbacks.rb:416:in `_run_save_callbacks'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/activesupport-3.0.10/lib/active_support/callbacks.rb:94:in `run_callbacks'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/mongo_mapper-0.9.2/lib/mongo_mapper/plugins/embedded_callbacks.rb:28:in `run_callbacks'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/mongo_mapper-0.9.2/lib/mongo_mapper/plugins/callbacks.rb:14:in `create_or_update'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/mongo_mapper-0.9.2/lib/mongo_mapper/plugins/querying.rb:143:in `save'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/mongo_mapper-0.9.2/lib/mongo_mapper/plugins/dirty.rb:20:in `block in save'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/mongo_mapper-0.9.2/lib/mongo_mapper/plugins/dirty.rb:42:in `clear_changes'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/mongo_mapper-0.9.2/lib/mongo_mapper/plugins/dirty.rb:20:in `save'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/mongo_mapper-0.9.2/lib/mongo_mapper/plugins/validations.rb:23:in `save'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/mongo_mapper-0.9.2/lib/mongo_mapper/plugins/querying.rb:30:in `block in create'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/mongo_mapper-0.9.2/lib/mongo_mapper/plugins/querying.rb:113:in `block in initialize_each'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/mongo_mapper-0.9.2/lib/mongo_mapper/plugins/querying.rb:111:in `each'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/mongo_mapper-0.9.2/lib/mongo_mapper/plugins/querying.rb:111:in `initialize_each'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/mongo_mapper-0.9.2/lib/mongo_mapper/plugins/querying.rb:30:in `create'
/var/www/fhsclock/admin/controllers/wallpapers.rb:13:in `block (2 levels) in <top (required)>'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/padrino-core-0.10.0/lib/padrino-core/application/routing.rb:486:in `call'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/padrino-core-0.10.0/lib/padrino-core/application/routing.rb:486:in `block in route'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/sinatra-1.2.7/lib/sinatra/base.rb:736:in `instance_eval'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/sinatra-1.2.7/lib/sinatra/base.rb:736:in `route_eval'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/padrino-core-0.10.0/lib/padrino-core/application/routing.rb:49:in `block (2 levels) in process_destination_path'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/padrino-core-0.10.0/lib/padrino-core/application/routing.rb:49:in `catch'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/padrino-core-0.10.0/lib/padrino-core/application/routing.rb:49:in `block in process_destination_path'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/padrino-core-0.10.0/lib/padrino-core/application/routing.rb:22:in `instance_eval'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/padrino-core-0.10.0/lib/padrino-core/application/routing.rb:22:in `process_destination_path'
(eval):16:in `block (2 levels) in inject_root_methods'
(eval):6:in `catch'
(eval):6:in `block in inject_root_methods'
(eval):313:in `block in inject_root_methods'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/http_router-0.8.11/lib/http_router/node/root.rb:68:in `[]'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/http_router-0.8.11/lib/http_router.rb:110:in `block in call'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/http_router-0.8.11/lib/http_router.rb:110:in `catch'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/http_router-0.8.11/lib/http_router.rb:110:in `call'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/padrino-core-0.10.0/lib/padrino-core/application/routing.rb:796:in `route!'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/padrino-core-0.10.0/lib/padrino-core/application/routing.rb:785:in `dispatch!'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/sinatra-1.2.7/lib/sinatra/base.rb:656:in `block in call!'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/sinatra-1.2.7/lib/sinatra/base.rb:820:in `block in invoke'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/sinatra-1.2.7/lib/sinatra/base.rb:820:in `catch'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/sinatra-1.2.7/lib/sinatra/base.rb:820:in `invoke'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/sinatra-1.2.7/lib/sinatra/base.rb:656:in `call!'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/sinatra-1.2.7/lib/sinatra/base.rb:641:in `call'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/rack-flash-0.1.2/lib/rack/flash.rb:147:in `call'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/padrino-core-0.10.0/lib/padrino-core/reloader.rb:243:in `call'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/padrino-core-0.10.0/lib/padrino-core/logger.rb:300:in `call'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/sinatra-1.2.7/lib/sinatra/showexceptions.rb:21:in `call'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/rack-1.3.5/lib/rack/session/abstract/id.rb:195:in `context'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/rack-1.3.5/lib/rack/session/abstract/id.rb:190:in `call'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/rack-1.3.5/lib/rack/head.rb:9:in `call'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/sinatra-1.2.7/lib/sinatra/showexceptions.rb:21:in `call'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/rack-1.3.5/lib/rack/methodoverride.rb:24:in `call'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/sinatra-1.2.7/lib/sinatra/base.rb:1292:in `block in call'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/sinatra-1.2.7/lib/sinatra/base.rb:1323:in `synchronize'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/sinatra-1.2.7/lib/sinatra/base.rb:1292:in `call'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/padrino-core-0.10.0/lib/padrino-core/router.rb:71:in `block in call'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/padrino-core-0.10.0/lib/padrino-core/router.rb:64:in `each'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/padrino-core-0.10.0/lib/padrino-core/router.rb:64:in `call'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/thin-1.2.11/lib/thin/connection.rb:84:in `block in pre_process'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/thin-1.2.11/lib/thin/connection.rb:82:in `catch'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/thin-1.2.11/lib/thin/connection.rb:82:in `pre_process'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/thin-1.2.11/lib/thin/connection.rb:57:in `process'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/thin-1.2.11/lib/thin/connection.rb:42:in `receive_data'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `run_machine'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `run'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/thin-1.2.11/lib/thin/backends/base.rb:61:in `start'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/thin-1.2.11/lib/thin/server.rb:159:in `start'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/rack-1.3.5/lib/rack/handler/thin.rb:13:in `run'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/rack-1.3.5/lib/rack/server.rb:265:in `start'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/padrino-core-0.10.0/lib/padrino-core/server.rb:44:in `start'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/padrino-core-0.10.0/lib/padrino-core/server.rb:34:in `start'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/padrino-core-0.10.0/lib/padrino-core/server.rb:13:in `run!'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/padrino-core-0.10.0/lib/padrino-core/cli/adapter.rb:7:in `start'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/padrino-core-0.10.0/lib/padrino-core/cli/base.rb:24:in `start'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/thor-0.14.6/lib/thor/task.rb:22:in `run'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/thor-0.14.6/lib/thor/invocation.rb:118:in `invoke_task'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/thor-0.14.6/lib/thor.rb:263:in `dispatch'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/thor-0.14.6/lib/thor/base.rb:389:in `start'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/gems/padrino-core-0.10.0/bin/padrino:9:in `<top (required)>'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/bin/padrino:19:in `load'
/home/ethan/.rvm/gems/ruby-1.9.2-p290#fhsclock/bin/padrino:19:in `<main>'
This thread on the MongoMapper group suggests that I run ensure_index (or create_index) on the files.chunk collection. However, I do not know how to do this with MongoMapper.
Is there a way to prevent this?
I had the same problem, and as the author suggests, the line:
db.fs.chunks.ensureIndex({files_id: 1, n: 1})
Inside mongo console helped.
Full algorithm is that:
Open terminal, type mongo. Press enter.
Type use <your database name>. Press enter.
Type db.fs.chunks.ensureIndex({files_id: 1, n: 1}). Press enter.
YourClassName.ensureIndex(:files_id)
Does the last answer in this thread help you out?
Once I removed :slave_ok => true from my database configuration, everything worked fine. According the MongoDB docs, it shouldn't even use the slave. But, whatever works...