{"record":{"id":"b2d5755f5d633730","repo":"puppetlabs/puppet","slug":"pp-syntax-checker-the-text-to-check-must-be-a-str","errorCode":null,"errorMessage":"PP syntax checker: the text to check must be a String.","messagePattern":"PP syntax checker: the text to check must be a String\\.","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/puppet/syntax_checkers/pp.rb","lineNumber":18,"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":"The PP syntax-checker plugin validates Puppet Language text and requires the text argument to be a String. Passing a parsed AST model, Symbol, or nil raises ArgumentError before Puppet::Pops::Parser::EvaluatingParser.singleton.parse_string is ever called. The checker backs 'pp' syntax validation of heredocs/templates and is the same code path used for template content checks.","triggerScenarios":"Calling Puppet::SyntaxCheckers::PP.new.check(nil, 'pp', acceptor, source_pos), or forwarding a parsed object/AST instead of source text. Typical when tooling fetches manifest content that can be nil (missing file, empty lookup) and forwards it unchecked.","commonSituations":"Custom lint wrappers that read files which may not exist (IO#read on a closed handle, nil from an optional config key), or tests that pass fixture objects rather than raw strings.","solutions":["Guard for nil before calling: skip or raise your own descriptive error when text is nil","Pass the literal source string (File.read result, template body)","Type-check at your API boundary: fail fast with the received class in the message"],"exampleFix":"# before\nchecker.check(params[:code], 'pp', acceptor, pos) # params[:code] may be nil => ArgumentError\n\n# after\ncode = params.fetch(:code)\nraise ArgumentError, 'code is required' if code.nil?\nchecker.check(code, 'pp', acceptor, pos)","handlingStrategy":"validation","validationCode":"raise ArgumentError, 'manifest text is required' if text.nil?\nraise ArgumentError, \"text must be a String, got #{text.class}\" unless text.is_a?(String)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Guard optional content for nil before validation","Pass source strings only, never AST or parsed models","Include the received class in your own fail-fast errors"],"tags":["puppet","pp","puppet-language","syntax-checker","argumenterror"],"backgroundTag":"invalid-argument-type","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}