{"record":{"id":"ccef62111c6a1b3f","repo":"puppetlabs/puppet","slug":"node-names-cannot-be-nil","errorCode":null,"errorMessage":"Node names cannot be nil","messagePattern":"Node names cannot be nil","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/puppet/node.rb","lineNumber":101,"sourceCode":"      @environment = Puppet.lookup(:environments).get!(env)\n    else\n      @environment = env\n    end\n\n    # Keep environment_name attribute and parameter in sync if they have been set\n    unless @environment.nil?\n      # always set the environment parameter. It becomes top scope $environment for a manifest during catalog compilation.\n      @parameters[ENVIRONMENT] = @environment.name.to_s\n      self.environment_name = @environment.name\n    end\n  end\n\n  def has_environment_instance?\n    !@environment.nil?\n  end\n\n  def initialize(name, options = {})\n    raise ArgumentError, _(\"Node names cannot be nil\") unless name\n\n    @name = name\n\n    classes = options[:classes]\n    if classes\n      if classes.is_a?(String)\n        @classes = [classes]\n      else\n        @classes = classes\n      end\n    else\n      @classes = []\n    end\n\n    @parameters = options[:parameters] || {}\n\n    @facts = options[:facts]\n","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/node.rb#L83-L119","documentation":"Puppet::Node.new raises ArgumentError immediately when the name argument is nil. The name keys catalogs, certificates and reports, so a node without an identity is meaningless and no defaulting is applied here; the caller must supply a truthy value, normally the certname.","triggerScenarios":"Puppet::Node.new(nil), Puppet::Node.new(options[:node_name]) where the option was never set, or building a node from a lookup (e.g. an ENC result or parameter) that returned nil.","commonSituations":"Wrapper scripts computing the node name from an unset variable; nil returned silently by an external node classifier; test fixtures that forget the name argument.","solutions":["Pass a concrete name, normally Puppet[:certname] or the request's node parameter","Default earlier in the call chain: name ||= Puppet[:certname] before constructing","Fix the upstream nil: find why the variable holding the name is empty","Add a unit test asserting a non-nil name at the construction site"],"exampleFix":"# before\nnode = Puppet::Node.new(params[:node])\n\n# after\nnode = Puppet::Node.new(params[:node] || Puppet[:certname])","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"def node_name?(value)\n  !value.nil? && (value.is_a?(String) || value.is_a?(Symbol)) && !value.to_s.empty?\nend\n\nraise ArgumentError, 'node name required' unless node_name?(name)","tryCatchPattern":null,"preventionTips":["Default node names to the certname at the system boundary","Fail fast on nil identity data; never pass nil through hoping for a downstream default"],"tags":["node","nil-argument","validation"],"backgroundTag":"nil-argument-rejected","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}