{"record":{"id":"d79d778fa582b934","repo":"puppetlabs/puppet","slug":"expected-pcallabletype-or-pvarianttype-thereof-go","errorCode":null,"errorMessage":"Expected PCallableType or PVariantType thereof, got %{type_class}","messagePattern":"Expected PCallableType or PVariantType thereof, got %(.+?)","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/puppet/functions.rb","lineNumber":492,"sourceCode":"    #\n    # @api public\n    def block_param(*type_and_name)\n      case type_and_name.size\n      when 0\n        type = @all_callables\n        name = :block\n      when 1\n        type = @all_callables\n        name = type_and_name[0]\n      when 2\n        type, name = type_and_name\n        type = Puppet::Pops::Types::TypeParser.singleton.parse(type, loader) unless type.is_a?(Puppet::Pops::Types::PAnyType)\n      else\n        raise ArgumentError, _(\"block_param accepts max 2 arguments (type, name), got %{size}.\") % { size: type_and_name.size }\n      end\n\n      unless Puppet::Pops::Types::TypeCalculator.is_kind_of_callable?(type, false)\n        raise ArgumentError, _(\"Expected PCallableType or PVariantType thereof, got %{type_class}\") % { type_class: type.class }\n      end\n\n      unless name.is_a?(Symbol)\n        raise ArgumentError, _(\"Expected block_param name to be a Symbol, got %{name_class}\") % { name_class: name.class }\n      end\n\n      if @block_type.nil?\n        @block_type = type\n        @block_name = name\n      else\n        raise ArgumentError, _('Attempt to redefine block')\n      end\n    end\n    alias required_block_param block_param\n\n    # Defines one optional block parameter that may appear last. If type or name is missing the\n    # defaults are \"any callable\", and the name is \"block\". The implementor of the dispatch target\n    # must use block = nil when it is optional (or an error is raised when the call is made).","sourceCodeStart":474,"sourceCodeEnd":510,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/functions.rb#L474-L510","documentation":"The type given to block_param must be callable: a PCallableType or a PVariantType of callables, checked with TypeCalculator.is_kind_of_callable?. A parsed String such as 'String' produces PStringType, which is not callable, so the definition fails with this ArgumentError.","triggerScenarios":"block_param 'String', :block, or block_param('Array', :block): the type string parses fine but does not describe a callable. Also triggered by passing a PAnyType subclass instance that is not callable.","commonSituations":"Authors assuming block_param takes the block's content type (for example 'String' for a block that yields strings) instead of the callable signature type.","solutions":["Describe the block's signature as a Callable, for example block_param 'Callable[Integer, Integer]', :block.","If any callable is acceptable, call block_param with no type at all.","For a block that may be absent, keep the Callable type and use optional_block_param so it is wrapped Optional."],"exampleFix":"# before: String is not a callable type\n block_param 'String', :block\n\n# after: describe the signature the block must have\n block_param 'Callable[Integer, Integer]', :block\n # or accept any callable: block_param","handlingStrategy":"type-guard","validationCode":"# Pre-parse and check the type exactly as the DSL will\nt = Puppet::Pops::Types::TypeParser.singleton.parse('Callable[Integer, Integer]')\nraise 'not a callable type' unless Puppet::Pops::Types::TypeCalculator.is_kind_of_callable?(t, false)","typeGuard":"callable_block_type = ->(type_string) {\n  t = type_string.is_a?(Puppet::Pops::Types::PAnyType) ? type_string :\n      Puppet::Pops::Types::TypeParser.singleton.parse(type_string)\n  Puppet::Pops::Types::TypeCalculator.is_kind_of_callable?(t, false)\n}\nraise ArgumentError, 'bad block type' unless callable_block_type.call('Callable[0,0]')","tryCatchPattern":null,"preventionTips":["Describe blocks with Callable[...] signatures, never with content types like 'String'.","When unsure, omit the type: bare block_param accepts any callable.","Pre-parse new Callable strings in a console before committing."],"tags":["puppet","functions","block-param","callable","type-validation"],"backgroundTag":"invalid-parameter-type","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}