puppetlabs/puppet · error · ArgumentError

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

Error message

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

What it means

The PP syntax checker requires the acceptor argument to be an instance of Puppet::Pops::Validation::Acceptor, the object that collects Diagnostic records. Passing any other type raises ArgumentError before parsing starts. The evaluator's built-in call path always constructs a fresh Acceptor, so this error indicates the checker API was invoked directly with a wrong collector object.

Source

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

# A syntax checker for JSON.
# @api public
require_relative '../../puppet/syntax_checkers'
class Puppet::SyntaxCheckers::PP < Puppet::Plugins::SyntaxCheckers::SyntaxChecker
  # Checks the text for Puppet Language 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 (only accepts 'pp')
  # @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, _("PP syntax checker: the text to check must be a String.") unless text.is_a?(String)
    raise ArgumentError, _("PP syntax checker: the syntax identifier must be a String, e.g. pp") unless syntax == 'pp'
    raise ArgumentError, _("PP syntax checker: invalid Acceptor, got: '%{klass}'.") % { klass: acceptor.class.name } unless acceptor.is_a?(Puppet::Pops::Validation::Acceptor)

    begin
      Puppet::Pops::Parser::EvaluatingParser.singleton.parse_string(text)
    rescue => e
      # Cap the message to 100 chars and replace newlines
      msg = _("PP syntax checker: \"%{message}\"") % { message: e.message().slice(0, 500).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_PP) { 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. Create the real collector: acceptor = Puppet::Pops::Validation::Acceptor.new
  2. Read findings via acceptor.diagnostics / acceptor.error_count after check returns
  3. Wrap the checker in your own function that owns acceptor construction so callers never pass one

Example fix

# before
checker.check(text, 'pp', MyLintCollector.new, pos) # => ArgumentError

# after
acceptor = Puppet::Pops::Validation::Acceptor.new
checker.check(text, 'pp', acceptor, pos)
acceptor.diagnostics.each { |d| report << d.message }
Defensive patterns

Strategy: type-guard

Validate before calling

raise ArgumentError, "acceptor must be Puppet::Pops::Validation::Acceptor" 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, 'pp', acceptor, pos)
rescue ArgumentError => e
  raise ConfigError, "PP checker API misused: #{e.message}"
end

Prevention

When it happens

Trigger: Calling Puppet::SyntaxCheckers::PP.new.check(text, 'pp', nil, source_pos) or passing a custom lint-collector/Array/spec-double as the acceptor. Seen in custom CI tooling and RSpec tests that wrap `puppet parser validate` semantics programmatically.

Common situations: Building custom manifest-lint pipelines, upgrading tooling where an older duck-typed collector was accepted, or stubbing the acceptor in tests with a generic double.

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/0a6d9b467d7b9694. Report an issue: GitHub.