{"record":{"id":"ad90a605f6f1b433","repo":"sds/overcommit","slug":"unable-to-load-hook-hook-name-e-ad90a6","errorCode":null,"errorMessage":"Unable to load hook '#{hook_name}': #{e}","messagePattern":"Unable to load hook '#(.+?)': #(.+?)","errorType":"exception","errorClass":"Overcommit::Exceptions::HookLoadError","httpStatus":null,"severity":"error","filePath":"lib/overcommit/hook_loader/plugin_hook_loader.rb","lineNumber":97,"sourceCode":"      hook_base = hook_module.const_get('Base')\n\n      # Implement a simple class that executes the command and returns pass/fail\n      # based on the exit status\n      hook_class = Class.new(hook_base) do\n        def run\n          result = @context.execute_hook(command)\n\n          if result.success?\n            :pass\n          else\n            [:fail, result.stdout + result.stderr]\n          end\n        end\n      end\n\n      hook_module.const_set(hook_name, hook_class).new(@config, @context)\n    rescue LoadError, NameError => e\n      raise Overcommit::Exceptions::HookLoadError,\n            \"Unable to load hook '#{hook_name}': #{e}\",\n            e.backtrace\n    end\n  end\nend\n","sourceCodeStart":79,"sourceCodeEnd":103,"githubUrl":"https://github.com/sds/overcommit/blob/fee0cd74b26eb81f64b43b7fab17bbb541575cc4/lib/overcommit/hook_loader/plugin_hook_loader.rb#L79-L103","documentation":"The ad hoc twin of the create_hook failure: for hooks declared only in .overcommit.yml (no plugin file), PluginHookLoader#create_ad_hoc_hook builds an anonymous subclass of the hook type's Base and registers it with const_set. The rescue fires when Overcommit::Hook.const_get(@context.hook_class_name) or const_get('Base') raises NameError - the configured hook type has no matching module or Base class - and wraps it as 'Unable to load hook'.","triggerScenarios":"An enabled ad hoc hook (a config-only entry with required_executable/command) runs during load_hooks when its hook type section does not match a module under Overcommit::Hook - e.g. a misspelled section key like 'Precommit:' instead of 'PreCommit:' - or the installed Overcommit defines no <Type>::Base for that hook type.","commonSituations":"Typo in a .overcommit.yml section header (Precommit vs PreCommit); copy-pasted config using a hook type the installed Overcommit version does not support; casing changed while refactoring YAML config.","solutions":["Check the wrapped NameError in the message - it names the constant that could not be resolved","Spell hook type sections with Overcommit's exact CamelCase names (PreCommit:, CommitMsg:, PrePush:) and put ad hoc hooks under those keys","Confirm the hook type exists in your installed version via 'overcommit --list' or Overcommit::Utils.supported_hook_types","Upgrade the overcommit gem if the config targets a newer hook type"],"exampleFix":"# before (.overcommit.yml)\nPrecommit:\n  MyCheck:\n    required_executable: ./bin/check.sh\n\n# after\nPreCommit:\n  MyCheck:\n    required_executable: ./bin/check.sh","handlingStrategy":"validation","validationCode":"require 'yaml'\nconfig = YAML.load_file('.overcommit.yml')\nknown = %w[plugin_directory gemfile verify_plugin_signatures] +\n        Overcommit::Utils.supported_hook_types.map { |t| Overcommit::Utils.camel_case(t) }\nunknown = config.keys.map(&:to_s) - known\nabort \"Unknown hook type section(s): #{unknown.join(', ')}\" unless unknown.empty?","typeGuard":"def supported_hook_section?(key)\n  Overcommit::Utils.supported_hook_types.any? { |t| Overcommit::Utils.camel_case(t) == key.to_s }\nend","tryCatchPattern":"begin\n  runner.run\nrescue Overcommit::Exceptions::HookLoadError => e\n  abort \"Fix .overcommit.yml hook type sections: #{e.message}\"\nend","preventionTips":["Validate .overcommit.yml section keys in CI with the snippet above","Copy section names from Overcommit's default config instead of typing them from memory"],"tags":["ruby","overcommit","ad-hoc-hook","yaml-config","nameerror"],"backgroundTag":"uninitialized-constant","analyzedSha":"fee0cd74b26eb81f64b43b7fab17bbb541575cc4","analyzedAt":"2026-08-23T04:07:28.153Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}