puppetlabs/puppet · error · ArgumentError

Json syntax checker: invalid Acceptor, got: '%{klass}'.

Error message

Json syntax checker: invalid Acceptor, got: '%{klass}'.

What it means

The JSON syntax checker requires the acceptor argument to be an instance of Puppet::Pops::Validation::Acceptor, the diagnostic collector that records validation findings. Any other class, including duck-typed objects implementing #accept, triggers ArgumentError before the JSON parse begins. The built-in invocation path (assert_external_syntax in the pops evaluator) always supplies a real Acceptor, so hitting this means the checker was called directly with a wrong collector.

Source

Thrown at lib/puppet/syntax_checkers/json.rb:20

# A syntax checker for JSON.
# @api public
require_relative '../../puppet/syntax_checkers'
class Puppet::SyntaxCheckers::Json < Puppet::Plugins::SyntaxCheckers::SyntaxChecker
  # Checks the text for JSON syntax issues and reports them to the given acceptor.
  #
  # Error messages from the checker are capped at 100 chars from the source text.
  #
  # @param text [String] The text to check
  # @param syntax [String] The syntax identifier in mime style (e.g. 'json', 'json-patch+json', 'xml', 'myapp+xml'
  # @param acceptor [#accept] A Diagnostic acceptor
  # @param source_pos [Puppet::Pops::Adapters::SourcePosAdapter] A source pos adapter with location information
  # @api public
  #
  def check(text, syntax, acceptor, source_pos)
    raise ArgumentError, _("Json syntax checker: the text to check must be a String.") unless text.is_a?(String)
    raise ArgumentError, _("Json syntax checker: the syntax identifier must be a String, e.g. json, data+json") unless syntax.is_a?(String)
    raise ArgumentError, _("Json syntax checker: invalid Acceptor, got: '%{klass}'.") % { klass: acceptor.class.name } unless acceptor.is_a?(Puppet::Pops::Validation::Acceptor)

    begin
      Puppet::Util::Json.load(text)
    rescue => e
      # Cap the message to 100 chars and replace newlines
      msg = _("JSON syntax checker: Cannot parse invalid JSON string. \"%{message}\"") % { message: e.message().slice(0, 100).gsub(/\r?\n/, "\\n") }

      # TODO: improve the pops API to allow simpler diagnostic creation while still maintaining capabilities
      # and the issue code. (In this case especially, where there is only a single error message being issued).
      #
      issue = Puppet::Pops::Issues.issue(:ILLEGAL_JSON) { msg }
      acceptor.accept(Puppet::Pops::Validation::Diagnostic.new(:error, issue, source_pos.file, source_pos, {}))
    end
  end
end

View on GitHub (pinned to e227c27540)

Solutions

  1. Use a real collector: acceptor = Puppet::Pops::Validation::Acceptor.new, call check, then read acceptor.diagnostics and acceptor.error_count
  2. For custom reporting, post-process acceptor.diagnostics instead of replacing the acceptor
  3. In specs, build the real Acceptor rather than stubbing it

Example fix

# before
checker.check(text, 'json', [], pos) # => ArgumentError

# after
acceptor = Puppet::Pops::Validation::Acceptor.new
checker.check(text, 'json', acceptor, pos)
raise 'invalid JSON' if acceptor.error_count > 0
Defensive patterns

Strategy: type-guard

Validate before calling

acceptor = Puppet::Pops::Validation::Acceptor.new unless acceptor.is_a?(Puppet::Pops::Validation::Acceptor)

Type guard

def valid_acceptor?(a)
  a.is_a?(Puppet::Pops::Validation::Acceptor)
end

Try / catch

begin
  checker.check(text, 'json', acceptor, pos)
rescue ArgumentError => e
  raise ConfigError, "JSON checker API misused: #{e.message}"
end

Prevention

When it happens

Trigger: Calling Puppet::SyntaxCheckers::Json.new.check(text, 'json', collector, source_pos) where collector is a custom class, an Array, a spec double, or nil. Common in RSpec tests and custom CI wrappers around Puppet's task-metadata/JSON validation.

Common situations: Writing custom tooling to validate tasks' metadata.json or JSON heredocs, reusing an old acceptor shim from earlier Puppet versions, or test doubles configured with instance_double on the wrong class.

Understand the failure class

Background: Invalid argument type errors: "must be of type string", "expected X, got Y", and ERR_INVALID_ARG_TYPE explained — this error's family across 15 libraries.

Related errors


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