{"record":{"id":"e34af4027d6aa7ad","repo":"puppetlabs/puppet","slug":"path-is-nil","errorCode":null,"errorMessage":"Path is nil","messagePattern":"Path is nil","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/puppet/util/filetype.rb","lineNumber":81,"sourceCode":"      rescue => detail\n        message = _(\"%{klass} could not write %{path}: %{detail}\") % { klass: self.class, path: @path, detail: detail }\n        Puppet.log_exception(detail, message)\n        raise Puppet::Error, message, detail.backtrace\n      end\n    end\n  end\n\n  def self.filetype(type)\n    @filetypes[type]\n  end\n\n  # Pick or create a filebucket to use.\n  def bucket\n    @bucket ||= Puppet::Type.type(:filebucket).mkdefaultbucket.bucket\n  end\n\n  def initialize(path, default_mode = nil)\n    raise ArgumentError, _(\"Path is nil\") if path.nil?\n\n    @path = path\n    @default_mode = default_mode\n  end\n\n  # Arguments that will be passed to the execute method. Will set the uid\n  # to the target user if the target user and the current user are not\n  # the same\n  def cronargs\n    uid = Puppet::Util.uid(@path)\n    if uid && uid == Puppet::Util::SUIDManager.uid\n      { :failonfail => true, :combine => true }\n    else\n      { :failonfail => true, :combine => true, :uid => @path }\n    end\n  end\n\n  # Operate on plain files.","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/util/filetype.rb#L63-L99","documentation":"Puppet::Util::FileType's constructor takes the path (or, for the crontab filetype, the user) that every later read/write uses; a nil path is meaningless and rejected immediately with ArgumentError 'Path is nil'. It usually indicates an upstream bug that failed to resolve a name before constructing the filetype.","triggerScenarios":"Puppet::Util::FileType.filetype(:flat).new(nil), most often because a resource parameter was nil at that point (provider code reading resource[:path] before it is set) or a nil variable slipped through right before the call.","commonSituations":"Providers reading a target/name property that is nil on the first run, defaulting logic that returns nil, and refactors that move filetype construction above name resolution.","solutions":["Trace where the nil comes from — log the resource title right before the call","Default the value explicitly (path || \"/etc/#{resource.title}.conf\") or fail with a clear message","Construct the filetype only after the resource's namevars are resolved"],"exampleFix":"# before\nft = Puppet::Util::FileType.filetype(:flat).new(resource[:path])\n# resource[:path] is nil => ArgumentError: Path is nil\n\n# after\npath = resource[:path] || \"/etc/#{resource.title}.conf\"\nraise ArgumentError, 'no path resolved' if path.nil?\nft = Puppet::Util::FileType.filetype(:flat).new(path)","handlingStrategy":"validation","validationCode":"raise ArgumentError, 'path required' if path.nil?\nft = Puppet::Util::FileType.filetype(:flat).new(path)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never build a FileType without a resolved, non-nil path","Default from resource.title or a sane constant when the parameter is absent"],"tags":["puppet","nil-guard","filetype","argument"],"backgroundTag":"nil-argument","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}