puppetlabs/puppet · error · ArgumentError

Only String, Regexp, Pattern-Type, and Regexp-Type are…

Error message

Only String, Regexp, Pattern-Type, and Regexp-Type are allowed: got '#{re.class}

What it means

A case-else guard in TypeFactory.pattern: the argument is not one of String, Regexp, PPatternType, or PRegexpType, so it cannot contribute a regex pattern.

Solutions

  1. Pass pattern arguments as Strings, Regexp instances, or Pattern/Regexp types
  2. Convert other objects to a Regexp or pattern String first
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at lib/puppet/pops/types/type_factory.rb:292 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of puppetlabs/puppet@e227c27540 (2026-08-21). Data as JSON: /api/errors/613c1c64a3703034. Report an issue: GitHub.

Appendix: source

Thrown at lib/puppet/pops/types/type_factory.rb:292

  def self.pattern(*regular_expressions)
    patterns = regular_expressions.map do |re|
      case re
      when String
        re_t = PRegexpType.new(re)
        re_t.regexp # compile it to catch errors
        re_t

      when Regexp
        PRegexpType.new(re)

      when PRegexpType
        re

      when PPatternType
        re.patterns

      else
        raise ArgumentError, "Only String, Regexp, Pattern-Type, and Regexp-Type are allowed: got '#{re.class}"
      end
    end.flatten.uniq
    PPatternType.new(patterns)
  end

  # Produces the Scalar type
  # @api public
  #
  def self.scalar
    PScalarType::DEFAULT
  end

  # Produces the ScalarData type
  # @api public
  #
  def self.scalar_data
    PScalarDataType::DEFAULT
  end

View on GitHub (pinned to e227c27540)