{"record":{"id":"f2282fc6f21ef5bc","repo":"puppetlabs/puppet","slug":"pp-syntax-checker-the-syntax-identifier-must-be-a","errorCode":null,"errorMessage":"PP syntax checker: the syntax identifier must be a String, e.g. pp","messagePattern":"PP syntax checker: the syntax identifier must be a String, e\\.g\\. pp","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/puppet/syntax_checkers/pp.rb","lineNumber":19,"sourceCode":"# frozen_string_literal: true\n\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":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/syntax_checkers/pp.rb#L1-L36","documentation":"Despite the message text ('must be a String, e.g. pp'), this ArgumentError fires unless syntax is exactly the String 'pp'. The guard is `unless syntax == 'pp'`, so a Symbol :pp, 'PP', 'pp ', or any other valid String like 'ruby' all raise. The checker only handles Puppet Language source, so the identifier must match its registry key 'pp' exactly.","triggerScenarios":"Calling the PP checker with :pp (Symbol), 'PP', or dispatching a checker by mime-style identifier and routing 'epp'/'ruby' content to the PP checker. Also hit when a syntax tag is built dynamically (string interpolation with trailing whitespace or newlines).","commonSituations":"Code that normalizes syntax tags with .upcase or .to_sym, generic checker-dispatch frameworks that try each registered checker in turn, or heredoc tags with invisible whitespace copied from documentation.","solutions":["Pass the exact literal 'pp' (lowercase String)","Normalize before dispatch: syntax.to_s.downcase.strip","Route by the checker registry key (Puppet.lookup(:plugins)[Puppet::Plugins::SyntaxCheckers::SYNTAX_CHECKERS_KEY]) instead of guessing a checker per identifier"],"exampleFix":"# before\nchecker.check(text, :pp, acceptor, pos) # => ArgumentError\n\n# after\nchecker.check(text, 'pp', acceptor, pos)","handlingStrategy":"validation","validationCode":"syntax = syntax.to_s.downcase.strip if syntax.respond_to?(:to_s)\nraise ArgumentError, \"unsupported syntax #{syntax.inspect}; PP checker accepts 'pp' only\" unless syntax == 'pp'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pass the literal 'pp'; the message about String is stricter than the check (exact equality)","Route by registry key instead of trying checkers with guessed identifiers","Test dispatch code with symbols, upcased and padded inputs"],"tags":["puppet","pp","syntax-checker","argumenterror","misleading-message"],"backgroundTag":"invalid-argument-type","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}