{"record":{"id":"0a6d9b467d7b9694","repo":"puppetlabs/puppet","slug":"pp-syntax-checker-invalid-acceptor-got-klass","errorCode":null,"errorMessage":"PP syntax checker: invalid Acceptor, got: '%{klass}'.","messagePattern":"PP syntax checker: invalid Acceptor, got: '%(.+?)'\\.","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/puppet/syntax_checkers/pp.rb","lineNumber":20,"sourceCode":"\n# A syntax checker for JSON.\n# @api public\nrequire_relative '../../puppet/syntax_checkers'\nclass Puppet::SyntaxCheckers::PP < Puppet::Plugins::SyntaxCheckers::SyntaxChecker\n  # Checks the text for Puppet Language syntax issues and reports them to the given acceptor.\n  #\n  # Error messages from the checker are capped at 100 chars from the source text.\n  #\n  # @param text [String] The text to check\n  # @param syntax [String] The syntax identifier in mime style (only accepts 'pp')\n  # @param acceptor [#accept] A Diagnostic acceptor\n  # @param source_pos [Puppet::Pops::Adapters::SourcePosAdapter] A source pos adapter with location information\n  # @api public\n  #\n  def check(text, syntax, acceptor, source_pos)\n    raise ArgumentError, _(\"PP syntax checker: the text to check must be a String.\") unless text.is_a?(String)\n    raise ArgumentError, _(\"PP syntax checker: the syntax identifier must be a String, e.g. pp\") unless syntax == 'pp'\n    raise ArgumentError, _(\"PP syntax checker: invalid Acceptor, got: '%{klass}'.\") % { klass: acceptor.class.name } unless acceptor.is_a?(Puppet::Pops::Validation::Acceptor)\n\n    begin\n      Puppet::Pops::Parser::EvaluatingParser.singleton.parse_string(text)\n    rescue => e\n      # Cap the message to 100 chars and replace newlines\n      msg = _(\"PP syntax checker: \\\"%{message}\\\"\") % { message: e.message().slice(0, 500).gsub(/\\r?\\n/, \"\\\\n\") }\n\n      # TODO: improve the pops API to allow simpler diagnostic creation while still maintaining capabilities\n      # and the issue code. (In this case especially, where there is only a single error message being issued).\n      #\n      issue = Puppet::Pops::Issues.issue(:ILLEGAL_PP) { msg }\n      acceptor.accept(Puppet::Pops::Validation::Diagnostic.new(:error, issue, source_pos.file, source_pos, {}))\n    end\n  end\nend\n","sourceCodeStart":2,"sourceCodeEnd":36,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/syntax_checkers/pp.rb#L2-L36","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Create the real collector: acceptor = Puppet::Pops::Validation::Acceptor.new","Read findings via acceptor.diagnostics / acceptor.error_count after check returns","Wrap the checker in your own function that owns acceptor construction so callers never pass one"],"exampleFix":"# before\nchecker.check(text, 'pp', MyLintCollector.new, pos) # => ArgumentError\n\n# after\nacceptor = Puppet::Pops::Validation::Acceptor.new\nchecker.check(text, 'pp', acceptor, pos)\nacceptor.diagnostics.each { |d| report << d.message }","handlingStrategy":"type-guard","validationCode":"raise ArgumentError, \"acceptor must be Puppet::Pops::Validation::Acceptor\" unless acceptor.is_a?(Puppet::Pops::Validation::Acceptor)","typeGuard":"def valid_acceptor?(a)\n  a.is_a?(Puppet::Pops::Validation::Acceptor)\nend","tryCatchPattern":"begin\n  checker.check(text, 'pp', acceptor, pos)\nrescue ArgumentError => e\n  raise ConfigError, \"PP checker API misused: #{e.message}\"\nend","preventionTips":["Construct Acceptor.new at the single wrapper that calls check","Use acceptor.error_count to branch after the call","Avoid stubbing the acceptor in tests; build the real object"],"tags":["puppet","pp","syntax-checker","argumenterror","api-misuse"],"backgroundTag":"invalid-argument-type","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}