puppetlabs/puppet · error · ArgumentError
Could not find %{request} to destroy
Error message
Could not find %{request} to destroy What it means
The memory terminus (used in tests and short-lived in-process caches) keeps instances in a hash keyed by request.key. destroy raises ArgumentError 'Could not find <key> to destroy' unless the key was previously saved via save; unlike the disk termini it does not emulate success on missing entries, so double destroys fail loudly.
Source
Thrown at lib/puppet/indirector/memory.rb:16
# frozen_string_literal: true
require_relative '../../puppet/indirector/terminus'
# Manage a memory-cached list of instances.
class Puppet::Indirector::Memory < Puppet::Indirector::Terminus
def initialize
clear
end
def clear
@instances = {}
end
def destroy(request)
raise ArgumentError, _("Could not find %{request} to destroy") % { request: request.key } unless @instances.include?(request.key)
@instances.delete(request.key)
end
def find(request)
@instances[request.key]
end
def search(request)
found_keys = @instances.keys.find_all { |key| key.include?(request.key) }
found_keys.collect { |key| @instances[key] }
end
def head(request)
!find(request).nil?
end
def save(request)View on GitHub (pinned to e227c27540)
Solutions
- Guard with find first: only destroy when terminus.find(request) returns a value.
- Rescue ArgumentError when cleanup is best-effort (e.g. in test teardown).
- Use clear to wipe all state instead of destroying keys one by one.
- Fix hook ordering so cleanup does not execute twice for the same key.
Example fix
# before
after { terminus.destroy(req) } # raises when the key was never saved / already destroyed
# after
after { terminus.destroy(req) if terminus.find(req) } Defensive patterns
Strategy: validation
Validate before calling
req = Puppet::Indirector::Request.new(indirection.name, :destroy, key, nil) terminus.destroy(req) if terminus.find(req)
Prevention
- Make test cleanup idempotent (find-before-destroy or clear).
- Do not assume memory terminus destroy matches disk termini, which emulate success on missing entries.
- Keep one cleanup owner per key in test harnesses.
When it happens
Trigger: Calling destroy twice for the same key; destroying after clear; rspec before/after hooks that both clean up; shared examples where the save step never ran.
Common situations: Test suites with double-running cleanup hooks; retry logic that assumes idempotent destroy; fixtures resetting state between hooks while the subject still holds stale references.
Related errors
- Listing remote file buckets is not allowed
- Invalid terminus name %{terminus_class}
- Could not find terminus %{terminus_class} for indirection %{
- Could not find terminus %{terminus_class} for indirection %{
- Could not read MessagePack data for %{indirection} %{key}: %
AI-assisted analysis of puppetlabs/puppet@e227c27540 (2026-08-21).
Data as JSON: /api/errors/05606a0ad5957bdf.
Report an issue: GitHub.