sds/overcommit · error · NotImplementedError

Hook must define `run`

Error message

Hook must define `run`

What it means

Error "Hook must define `run`" thrown in sds/overcommit.

Source

Thrown at lib/overcommit/hook/base.rb:34

  MESSAGE_TYPES = [:error, :warning].freeze

  # Functionality common to all hooks.
  class Base # rubocop:disable Metrics/ClassLength
    extend Forwardable

    def_delegators :@context, :all_files, :modified_files
    attr_reader :config

    # @param config [Overcommit::Configuration]
    # @param context [Overcommit::HookContext]
    def initialize(config, context)
      @config = config.for_hook(self)
      @context = context
    end

    # Runs the hook.
    def run
      raise NotImplementedError, 'Hook must define `run`'
    end

    # Runs the hook and transforms the status returned based on the hook's
    # configuration.
    #
    # Poorly named because we already have a bunch of hooks in the wild that
    # implement `#run`, and we needed a wrapper step to transform the status
    # based on any custom configuration.
    def run_and_transform
      if output = check_for_requirements
        status = :fail
      else
        result = Overcommit::Utils.with_environment(@config.fetch('env') { {} }) { run }
        status, output = process_hook_return_value(result)
      end

      [transform_status(status), output]
    end

View on GitHub (pinned to fee0cd74b2)

Solutions

  1. Define a `run` method in your custom hook class that returns :pass, :fail, or :warn (via the `pass`/`fail`/`warn` helpers or Message objects).
  2. Ensure your hook inherits from the correct Overcommit hook base class (e.g. Overcommit::Hook::PreCommit::Base) so the run contract applies.

When it happens

Trigger: Thrown at lib/overcommit/hook/base.rb:34 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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