{"record":{"id":"ea8402270cbfecb1","repo":"puppetlabs/puppet","slug":"json-syntax-checker-invalid-acceptor-got-kla","errorCode":null,"errorMessage":"Json syntax checker: invalid Acceptor, got: '%{klass}'.","messagePattern":"Json syntax checker: invalid Acceptor, got: '%(.+?)'\\.","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/puppet/syntax_checkers/json.rb","lineNumber":20,"sourceCode":"\n# A syntax checker for JSON.\n# @api public\nrequire_relative '../../puppet/syntax_checkers'\nclass Puppet::SyntaxCheckers::Json < Puppet::Plugins::SyntaxCheckers::SyntaxChecker\n  # Checks the text for JSON 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 (e.g. 'json', 'json-patch+json', 'xml', 'myapp+xml'\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, _(\"Json syntax checker: the text to check must be a String.\") unless text.is_a?(String)\n    raise ArgumentError, _(\"Json syntax checker: the syntax identifier must be a String, e.g. json, data+json\") unless syntax.is_a?(String)\n    raise ArgumentError, _(\"Json syntax checker: invalid Acceptor, got: '%{klass}'.\") % { klass: acceptor.class.name } unless acceptor.is_a?(Puppet::Pops::Validation::Acceptor)\n\n    begin\n      Puppet::Util::Json.load(text)\n    rescue => e\n      # Cap the message to 100 chars and replace newlines\n      msg = _(\"JSON syntax checker: Cannot parse invalid JSON string. \\\"%{message}\\\"\") % { message: e.message().slice(0, 100).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_JSON) { 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/json.rb#L2-L36","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Use a real collector: acceptor = Puppet::Pops::Validation::Acceptor.new, call check, then read acceptor.diagnostics and acceptor.error_count","For custom reporting, post-process acceptor.diagnostics instead of replacing the acceptor","In specs, build the real Acceptor rather than stubbing it"],"exampleFix":"# before\nchecker.check(text, 'json', [], pos) # => ArgumentError\n\n# after\nacceptor = Puppet::Pops::Validation::Acceptor.new\nchecker.check(text, 'json', acceptor, pos)\nraise 'invalid JSON' if acceptor.error_count > 0","handlingStrategy":"type-guard","validationCode":"acceptor = Puppet::Pops::Validation::Acceptor.new 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, 'json', acceptor, pos)\nrescue ArgumentError => e\n  raise ConfigError, \"JSON checker API misused: #{e.message}\"\nend","preventionTips":["Own acceptor construction in a wrapper so callers never pass one","Post-process acceptor.diagnostics instead of replacing the collector","Double-check the class when upgrading Puppet versions in custom tooling"],"tags":["puppet","json","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"}