{"record":{"id":"c1316d096af2390b","repo":"puppetlabs/puppet","slug":"from-must-be-less-or-equal-to-to-got-from-c1316d","errorCode":null,"errorMessage":"'from' must be less or equal to 'to'. Got (#{from}, #{to}","messagePattern":"'from' must be less or equal to 'to'\\. Got \\(#(.+?), #(.+?)","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/puppet/pops/types/types.rb","lineNumber":943,"sourceCode":"          end\n        end\n      end\n\n      def on_error(from, abs = false)\n        if from.is_a?(String)\n          _(\"The string '%{str}' cannot be converted to Numeric\") % { str: from }\n        else\n          t = TypeCalculator.singleton.infer(from).generalize\n          _(\"Value of type %{type} cannot be converted to Numeric\") % { type: t }\n        end\n      end\n    end\n  end\n\n  def initialize(from, to = Float::INFINITY)\n    from = -Float::INFINITY if from.nil? || from == :default\n    to = Float::INFINITY if to.nil? || to == :default\n    raise ArgumentError, \"'from' must be less or equal to 'to'. Got (#{from}, #{to}\" if from > to\n\n    @from = from\n    @to = to\n  end\n\n  # Checks if this numeric range intersects with another\n  #\n  # @param o [PNumericType] the range to compare with\n  # @return [Boolean] `true` if this range intersects with the other range\n  # @api public\n  def intersect?(o)\n    instance_of?(o.class) && !(@to < o.numeric_from || o.numeric_to < @from)\n  end\n\n  # Returns the lower bound of the numeric range or `nil` if no lower bound is set.\n  # @return [Float,Integer]\n  def from\n    @from == -Float::INFINITY ? nil : @from","sourceCodeStart":925,"sourceCodeEnd":961,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/pops/types/types.rb#L925-L961","documentation":"Puppet's type system models numeric ranges (Integer[from, to], Float[from, to]) with subclasses of PNumericType. The constructor rewrites nil or :default to -/+Float::INFINITY and then enforces the invariant from <= to, because an inverted range is meaningless. In manifests this surfaces as Integer[10, 2] or Float[$a, $b] with $a > $b; from Ruby it comes from PIntegerType.new(10, 2). The message prints both offending bounds.","triggerScenarios":"Writing Integer[5, 1] or Float[10, 0.5] in Puppet DSL; calling PIntegerType.new(from, to) / PFloatType.new(from, to) in Ruby with from > to; range endpoints taken from variables, facts or class parameters that arrive in the wrong order (for example Integer[$port_max, $port_min]).","commonSituations":"A manifest parameter pair meant to be min/max gets swapped by the user; computed ranges (port windows, pagination) that are never sorted before use; Ruby wrapper code feeding unvalidated input straight into the type constructor; copy-pasting an example with the bounds reversed.","solutions":["Order the bounds so the lower value comes first: Integer[2, 10] instead of Integer[10, 2].","If the pair comes from user input, sort it before use: $bounds = [$a, $b].sort; Integer[$bounds[0], $bounds[1]].","Use undef (DSL) or nil / :default (Ruby) for an open end instead of a number, e.g. Integer[1, default].","In Ruby, validate from <= to before calling PIntegerType.new and raise your own descriptive error."],"exampleFix":"# before (Puppet DSL)\nInteger[$high, $low]   # ArgumentError: 'from' must be less or equal to 'to' when $high > $low\n\n# after\n$bounds = [$low, $high].sort\nInteger[$bounds[0], $bounds[1]]","handlingStrategy":"validation","validationCode":"# Ruby: normalize and check before constructing\nfrom = -Float::INFINITY if from.nil? || from == :default\nto   =  Float::INFINITY if to.nil?   || to == :default\nraise ArgumentError, \"inverted range (#{from}, #{to})\" unless from <= to\nPIntegerType.new(from, to)","typeGuard":"def valid_numeric_range?(from, to)\n  [from, to].all? { |v| v.nil? || v == :default || v.is_a?(Numeric) } &&\n    (from.nil? || from == :default || to.nil? || to == :default || from <= to)\nend","tryCatchPattern":"begin\n  PIntegerType.new(from, to)\nrescue ArgumentError\n  from, to = [from, to].minmax   # both Numeric: normalize inverted bounds\n  retry\nend","preventionTips":["Normalize range endpoints (sort the pair) before passing them to type constructors.","Prefer undef / :default for open-ended bounds instead of sentinel numbers.","Wrap type construction in a helper that validates from <= to and raises a contextual error."],"tags":["puppet","type-system","numeric-range","argument-validation"],"backgroundTag":"invalid-range-arguments","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}