{"record":{"id":"f72bcc3a82ac344f","repo":"sds/overcommit","slug":"a-load-error-occurred-did-you-forget-to-install-a","errorCode":null,"errorMessage":"A load error occurred. Did you forget to install a gem?\n#{e.message}","messagePattern":"A load error occurred\\. Did you forget to install a gem\\?\n#(.+?)","errorType":"exception","errorClass":"Overcommit::Exceptions::HookLoadError","httpStatus":null,"severity":"error","filePath":"lib/overcommit/hook_runner.rb","lineNumber":215,"sourceCode":"    end\n\n    def load_hooks\n      require \"overcommit/hook/#{@context.hook_type_name}/base\"\n\n      @hooks += HookLoader::BuiltInHookLoader.new(@config, @context, @log).load_hooks\n\n      # Load plugin hooks after so they can subclass existing hooks\n      @hooks += HookLoader::PluginHookLoader.new(@config, @context, @log).load_hooks\n    rescue LoadError => e\n      # Include a more helpful message that will probably save some confusion\n      message = 'A load error occurred. ' +\n        if @config['gemfile']\n          \"Did you forget to specify a gem in your `#{@config['gemfile']}`?\"\n        else\n          'Did you forget to install a gem?'\n        end\n\n      raise Overcommit::Exceptions::HookLoadError,\n            \"#{message}\\n#{e.message}\",\n            e.backtrace\n    end\n  end\nend\n","sourceCodeStart":197,"sourceCodeEnd":221,"githubUrl":"https://github.com/sds/overcommit/blob/fee0cd74b26eb81f64b43b7fab17bbb541575cc4/lib/overcommit/hook_runner.rb#L197-L221","documentation":"HookRunner#load_hooks requires the hook type base file and every built-in/plugin hook file; any LoadError escaping is re-raised as HookLoadError with a gem hint - 'Did you forget to install a gem?' or, when .overcommit.yml sets gemfile:, 'Did you forget to specify a gem in your <Gemfile>?'. It almost always means a gem a hook depends on is not installed in the Bundler context Overcommit runs under.","triggerScenarios":"require 'overcommit/hook/<type>/base' or a hook's own require of a gem raises LoadError: the gemfile option points at a Gemfile that lacks the gem, bundle install was never run, or overcommit runs without 'bundle exec' so Bundler.setup did not activate the gem.","commonSituations":"Fresh clone without bundle install; .overcommit.yml names a non-default Gemfile (gemfile: Gemfile.ci) missing hook dependencies; running a system-installed overcommit instead of bundle exec; CI image trimmed of dev gems.","solutions":["Run 'bundle install' (or 'bundle install --gemfile=<value of the gemfile option>') and retry the hook","Add the missing gem named in the LoadError to the Gemfile referenced by .overcommit.yml - and make sure the overcommit gem itself is in it","Invoke hooks through 'bundle exec overcommit' so the bundle context is active","If the gemfile option points at the wrong file, fix or remove it in .overcommit.yml"],"exampleFix":"# before\n$ git commit -m 'x'\nA load error occurred. Did you forget to specify a gem in your `Gemfile`?\ncannot load such file -- rubocop\n\n# after (Gemfile)\ngem 'overcommit'\ngem 'rubocop'\n\n$ bundle install && overcommit --sign pre-commit","handlingStrategy":"validation","validationCode":"def hook_dependencies_satisfied?(gemfile = nil)\n  cmd = gemfile ? ['bundle', 'check', \"--gemfile=#{gemfile}\"] : ['bundle', 'check']\n  system(*cmd, out: File::NULL, err: File::NULL)\nend\n\nabort 'Run bundle install before committing' unless hook_dependencies_satisfied?(config['gemfile'])","typeGuard":null,"tryCatchPattern":"begin\n  Overcommit::Runner.new(config, context, logger, printer).run\nrescue Overcommit::Exceptions::HookLoadError => e\n  if e.message =~ /load error occurred/i\n    warn 'Hook dependencies missing - run bundle install'\n    exit 78\n  end\n  raise\nend","preventionTips":["Document 'bundle install' as step one of repo bootstrap","Run 'overcommit --run <hook>' once in CI so missing gems fail the build, not the commit","Keep the gemfile option pointing at a committed Gemfile and Gemfile.lock"],"tags":["ruby","bundler","gem","loaderror","overcommit"],"backgroundTag":"missing-gem","analyzedSha":"fee0cd74b26eb81f64b43b7fab17bbb541575cc4","analyzedAt":"2026-08-23T04:07:28.153Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}