puppetlabs/puppet · error · ArgumentError

Path is nil

Error message

Path is nil

What it means

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.

Source

Thrown at lib/puppet/util/filetype.rb:81

      rescue => detail
        message = _("%{klass} could not write %{path}: %{detail}") % { klass: self.class, path: @path, detail: detail }
        Puppet.log_exception(detail, message)
        raise Puppet::Error, message, detail.backtrace
      end
    end
  end

  def self.filetype(type)
    @filetypes[type]
  end

  # Pick or create a filebucket to use.
  def bucket
    @bucket ||= Puppet::Type.type(:filebucket).mkdefaultbucket.bucket
  end

  def initialize(path, default_mode = nil)
    raise ArgumentError, _("Path is nil") if path.nil?

    @path = path
    @default_mode = default_mode
  end

  # Arguments that will be passed to the execute method. Will set the uid
  # to the target user if the target user and the current user are not
  # the same
  def cronargs
    uid = Puppet::Util.uid(@path)
    if uid && uid == Puppet::Util::SUIDManager.uid
      { :failonfail => true, :combine => true }
    else
      { :failonfail => true, :combine => true, :uid => @path }
    end
  end

  # Operate on plain files.

View on GitHub (pinned to e227c27540)

Solutions

  1. Trace where the nil comes from — log the resource title right before the call
  2. Default the value explicitly (path || "/etc/#{resource.title}.conf") or fail with a clear message
  3. Construct the filetype only after the resource's namevars are resolved

Example fix

# before
ft = Puppet::Util::FileType.filetype(:flat).new(resource[:path])
# resource[:path] is nil => ArgumentError: Path is nil

# after
path = resource[:path] || "/etc/#{resource.title}.conf"
raise ArgumentError, 'no path resolved' if path.nil?
ft = Puppet::Util::FileType.filetype(:flat).new(path)
Defensive patterns

Strategy: validation

Validate before calling

raise ArgumentError, 'path required' if path.nil?
ft = Puppet::Util::FileType.filetype(:flat).new(path)

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of puppetlabs/puppet@e227c27540 (2026-08-21). Data as JSON: /api/errors/e34af4027d6aa7ad. Report an issue: GitHub.