puppetlabs/puppet · error · ArgumentError
You can only save objects that respond to :name
Error message
You can only save objects that respond to :name
What it means
The YAML terminus's save() derives the storage path from the object's name, so it requires request.instance to respond to :name; anything else raises ArgumentError immediately, before any file I/O. This is a duck-type contract check: only name-addressed model objects (nodes, facts, reports) can be stored in the yaml indirection store.
Source
Thrown at lib/puppet/indirector/yaml.rb:22
require_relative '../../puppet/util/yaml'
# The base class for YAML indirection termini.
class Puppet::Indirector::Yaml < Puppet::Indirector::Terminus
# Read a given name's file in and convert it from YAML.
def find(request)
file = path(request.key)
return nil unless Puppet::FileSystem.exist?(file)
begin
load_file(file)
rescue Puppet::Util::Yaml::YamlLoadError => detail
raise Puppet::Error, _("Could not parse YAML data for %{indirection} %{request}: %{detail}") % { indirection: indirection.name, request: request.key, detail: detail }, detail.backtrace
end
end
# Convert our object to YAML and store it to the disk.
def save(request)
raise ArgumentError, _("You can only save objects that respond to :name") unless request.instance.respond_to?(:name)
file = path(request.key)
basedir = File.dirname(file)
# This is quite likely a bad idea, since we're not managing ownership or modes.
Dir.mkdir(basedir) unless Puppet::FileSystem.exist?(basedir)
begin
Puppet::Util::Yaml.dump(request.instance, file)
rescue TypeError => detail
Puppet.err _("Could not save %{indirection} %{request}: %{detail}") % { indirection: name, request: request.key, detail: detail }
end
end
# Return the path to a given node's file.
def path(name, ext = '.yaml')
if name =~ Puppet::Indirector::BadNameRegexp thenView on GitHub (pinned to e227c27540)
Solutions
- Save proper model instances: build the object with Puppet::Node.new(name, ...) / Puppet::Node::Facts.new(name, values) and save that
- For arbitrary data, use Puppet::Util::Yaml.dump(data, path) directly instead of the indirection
- If wrapping a model, delegate name (def name; @target.name; end) so the contract holds
- Check respond_to?(:name) at the call site for clearer failure context
Example fix
# before
Puppet::Node.indirection.save({ 'hostname' => 'web01' }, 'web01')
# => ArgumentError: You can only save objects that respond to :name
# after
node = Puppet::Node.new('web01', parameters: { 'hostname' => 'web01' })
Puppet::Node.indirection.save(node, 'web01') Defensive patterns
Strategy: type-guard
Validate before calling
unless request.instance.respond_to?(:name) raise ArgumentError, 'only name-bearing model objects can be saved; wrap raw data or use Puppet::Util::Yaml.dump' end
Type guard
def name_bearing?(obj) obj.respond_to?(:name) end
Prevention
- Route arbitrary data dumps to Puppet::Util::Yaml.dump, not the indirection
- Expose save paths only through model constructors so the contract is enforced by types
- Wrap third-party objects with a name delegator before storing
When it happens
Trigger: Calling Puppet::Node.indirection.save (or another yaml-backed indirection) with a Hash, Array, String, Struct, or any object lacking a name method; passing a wrapper/decorator that forwards most calls but not name.
Common situations: Custom tooling that tries to persist arbitrary configuration hashes through the yaml terminus instead of using its own storage; refactors wrapping model objects; test code saving raw data structures for later inspection.
Related errors
- Could not find indirection '%{indirection}'
- Could not understand URL %{key}: %{detail}
- Could not parse YAML data for %{indirection} %{request}: %{d
- puppet.tasks/unparseable-metadata
- #{path}: #{detail.message}
AI-assisted analysis of puppetlabs/puppet@e227c27540 (2026-08-21).
Data as JSON: /api/errors/212774bc08207f34.
Report an issue: GitHub.