{"record":{"id":"57b31f2b4c49af4c","repo":"puppetlabs/puppet","slug":"unable-to-load-application-class-class-name-f","errorCode":null,"errorMessage":"Unable to load application class '%{class_name}' from file 'puppet/application/%{application_name}.rb'","messagePattern":"Unable to load application class '%(.+?)' from file 'puppet/application/%(.+?)\\.rb'","errorType":"exception","errorClass":"Puppet::Error","httpStatus":null,"severity":"error","filePath":"lib/puppet/application.rb","lineNumber":254,"sourceCode":"      class_name = Puppet::Util::ConstantInflector.file2constant(application_name.to_s)\n\n      clazz = try_load_class(class_name)\n\n      ################################################################\n      #### Begin 2.7.x backward compatibility hack;\n      ####  eventually we need to issue a deprecation warning here,\n      ####  and then get rid of this stanza in a subsequent release.\n      ################################################################\n      if clazz.nil?\n        class_name = application_name.capitalize\n        clazz = try_load_class(class_name)\n      end\n      ################################################################\n      #### End 2.7.x backward compatibility hack\n      ################################################################\n\n      if clazz.nil?\n        raise Puppet::Error, _(\"Unable to load application class '%{class_name}' from file 'puppet/application/%{application_name}.rb'\") % { class_name: class_name, application_name: application_name }\n      end\n\n      clazz\n    end\n\n    # Given the fully qualified name of a class, attempt to get the class instance.\n    # @param [String] class_name the fully qualified name of the class to try to load\n    # @return [Class] the Class instance, or nil? if it could not be loaded.\n    def try_load_class(class_name)\n      const_defined?(class_name) ? const_get(class_name) : nil\n    end\n    private :try_load_class\n\n    # Return an instance of the specified application.\n    #\n    # @param [Symbol] name the lowercase name of the application\n    # @return [Puppet::Application] an instance of the specified name\n    # @raise [Puppet::Error] if the application class was not found.","sourceCodeStart":236,"sourceCodeEnd":272,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/application.rb#L236-L272","documentation":"Puppet::Application.find resolves 'puppet <name>' by loading puppet/application/<name>.rb and looking up the constant Puppet::Application::<name.capitalize> (plus a 2.7.x compatibility fallback). If the constant still isn't defined after that, Puppet::Error is raised: the file was found on the load path but did not define the expected class.","triggerScenarios":"Shipping lib/puppet/application/my_tool.rb that defines Puppet::Application::MyTool — 'my_tool'.capitalize is 'My_tool', so underscored compound names never match unless the constant is cased exactly as capitalize produces; the file failing to require cleanly; the class defined under a different namespace.","commonSituations":"Face/application plugins from modules or gems with naming mismatches; plugin upgrades that renamed the class; authors assuming Rails-style camelize instead of String#capitalize.","solutions":["Name the class exactly as String#capitalize will produce from the file name: mytool.rb defines Puppet::Application::Mytool; prefer single-token application names to sidestep capitalize's behavior on underscores","Verify it loads standalone: ruby -e \"require 'puppet/application/mytool'; p Puppet::Application::Mytool\"","Ensure the file is on $LOAD_PATH (module lib dir actually deployed to the node) and has no silent require failures","Check for typos between the subcommand word and the file name first — find only loads the matching file"],"exampleFix":"# lib/puppet/application/my_tool.rb\n# before\nmodule Puppet; module Application\nclass MyApp < Puppet::Application  # 'my_tool'.capitalize == 'My_tool', no match\nend; end; end\n\n# after  (or rename the file/command to 'myapp')\nmodule Puppet; module Application\nclass My_tool < Puppet::Application  # matches Application.find lookup\nend; end; end","handlingStrategy":"validation","validationCode":"require 'puppet/application/mytool'\nraise LoadError, 'plugin broken' unless Puppet::Application.const_defined?(:Mytool)","typeGuard":null,"tryCatchPattern":"begin\n  Puppet::Application.find('mytool')\nrescue Puppet::Error => e\n  # class/file naming mismatch — check e.message for expected class name\n  raise \"mytool plugin failed to load: #{e.message}\"\nend","preventionTips":["Follow the naming law exactly: puppet/application/<name>.rb must define Puppet::Application::<name.capitalize>","Prefer single-token application names to avoid String#capitalize surprises on underscores","Add a smoke test that requires every shipped application file and asserts the constant exists"],"tags":["plugin","load-error","application","puppet"],"backgroundTag":"plugin-load-failure","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}