{"record":{"id":"03ce9c02fea2f676","repo":"sds/overcommit","slug":"unable-to-load-hook-hook-name-e","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/base.rb","lineNumber":42,"sourceCode":"\n    attr_reader :log\n\n    # Load and return a {Hook} from a CamelCase hook name.\n    def create_hook(hook_name)\n      hook_type_class = Overcommit::Hook.const_get(@context.hook_class_name)\n      hook_base_class = hook_type_class.const_get(:Base)\n      hook_class = hook_type_class.const_get(hook_name)\n      unless hook_class < hook_base_class\n        raise Overcommit::Exceptions::HookLoadError,\n              \"Class #{hook_name} is not a subclass of #{hook_base_class}.\"\n      end\n\n      begin\n        Overcommit::Hook.const_get(@context.hook_class_name).\n                         const_get(hook_name).\n                         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\n  end\nend\n","sourceCodeStart":24,"sourceCodeEnd":49,"githubUrl":"https://github.com/sds/overcommit/blob/fee0cd74b26eb81f64b43b7fab17bbb541575cc4/lib/overcommit/hook_loader/base.rb#L24-L49","documentation":"Raised when instantiating a hook class fails with LoadError or NameError after the class resolved. Base#create_hook calls Hook::<Type>.const_get(hook_name).new(config, context) and wraps any LoadError/NameError as HookLoadError, keeping the original message and backtrace, because the missing constant or file usually points to an unloaded gem or a plugin file/class name mismatch.","triggerScenarios":"The plugin class body or its initialize references an uninitialized constant (e.g. a gem class never required); the plugin file never defined the expected CamelCase constant so const_get(hook_name) raises NameError (file my_check.rb defining class MyChek); or plugin code calls require on a file or gem that cannot be found.","commonSituations":"Plugin uses a gem constant without requiring the gem; typo between plugin file name and class name; plugin depends on a constant defined in another plugin file that sorts later during load; an Overcommit upgrade renamed a hook class the plugin reopened.","solutions":["Read the tail of the message after the colon - it carries the original NameError/LoadError naming the missing constant or file; fix that first","If a gem constant is missing, add the require at the top of the plugin file and add the gem to the bundle","If the hook class was never defined, make the class name the exact CamelCase of the file name (my_check.rb -> MyCheck) inside the correct hook module","If the dependency lives in another plugin, load it with require_relative or inline it so load order cannot break"],"exampleFix":"# before (.overcommit/plugins/pre_commit/json_lint.rb)\nmodule Overcommit::Hook::PreCommit\n  class JsonLint < Base\n    def run\n      JsLint.check(applicable_files) # NameError: uninitialized constant JsLint\n    end\n  end\nend\n\n# after\nrequire 'js_lint'\n\nmodule Overcommit::Hook::PreCommit\n  class JsonLint < Base\n    def run\n      JsLint.check(applicable_files)\n    end\n  end\nend","handlingStrategy":"try-catch","validationCode":"# CI smoke test: every plugin must load standalone\nDir[File.expand_path('.overcommit/plugins/**/*.rb')].sort.each { |f| require f }","typeGuard":null,"tryCatchPattern":"begin\n  hooks = Overcommit::HookLoader::PluginHookLoader.new(config, context, logger).load_hooks\nrescue Overcommit::Exceptions::HookLoadError => e\n  warn \"Plugin failed to load: #{e.message}\"\n  warn e.backtrace.first(5)\n  exit 78 # EX_CONFIG\nend","preventionTips":["require every gem a plugin uses at the top of the plugin file","Run a rake/CI task that requires all plugins on every push","Name plugin classes exactly after their file so const_get always resolves"],"tags":["ruby","overcommit","plugin","nameerror","loaderror","const-get"],"backgroundTag":"uninitialized-constant","analyzedSha":"fee0cd74b26eb81f64b43b7fab17bbb541575cc4","analyzedAt":"2026-08-23T04:07:28.153Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}