sds/overcommit · error · Overcommit::Exceptions::HookLoadError

A load error occurred. Did you forget to install a gem? #{e.

Error message

A load error occurred. Did you forget to install a gem?
#{e.message}

What it means

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.

Source

Thrown at lib/overcommit/hook_runner.rb:215

    end

    def load_hooks
      require "overcommit/hook/#{@context.hook_type_name}/base"

      @hooks += HookLoader::BuiltInHookLoader.new(@config, @context, @log).load_hooks

      # Load plugin hooks after so they can subclass existing hooks
      @hooks += HookLoader::PluginHookLoader.new(@config, @context, @log).load_hooks
    rescue LoadError => e
      # Include a more helpful message that will probably save some confusion
      message = 'A load error occurred. ' +
        if @config['gemfile']
          "Did you forget to specify a gem in your `#{@config['gemfile']}`?"
        else
          'Did you forget to install a gem?'
        end

      raise Overcommit::Exceptions::HookLoadError,
            "#{message}\n#{e.message}",
            e.backtrace
    end
  end
end

View on GitHub (pinned to fee0cd74b2)

Solutions

  1. Run 'bundle install' (or 'bundle install --gemfile=<value of the gemfile option>') and retry the hook
  2. 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
  3. Invoke hooks through 'bundle exec overcommit' so the bundle context is active
  4. If the gemfile option points at the wrong file, fix or remove it in .overcommit.yml

Example fix

# before
$ git commit -m 'x'
A load error occurred. Did you forget to specify a gem in your `Gemfile`?
cannot load such file -- rubocop

# after (Gemfile)
gem 'overcommit'
gem 'rubocop'

$ bundle install && overcommit --sign pre-commit
Defensive patterns

Strategy: validation

Validate before calling

def hook_dependencies_satisfied?(gemfile = nil)
  cmd = gemfile ? ['bundle', 'check', "--gemfile=#{gemfile}"] : ['bundle', 'check']
  system(*cmd, out: File::NULL, err: File::NULL)
end

abort 'Run bundle install before committing' unless hook_dependencies_satisfied?(config['gemfile'])

Try / catch

begin
  Overcommit::Runner.new(config, context, logger, printer).run
rescue Overcommit::Exceptions::HookLoadError => e
  if e.message =~ /load error occurred/i
    warn 'Hook dependencies missing - run bundle install'
    exit 78
  end
  raise
end

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of sds/overcommit@fee0cd74b2 (2026-08-23). Data as JSON: /api/errors/f72bcc3a82ac344f. Report an issue: GitHub.