{"record":{"id":"fff10c46e07fcbef","repo":"puppetlabs/puppet","slug":"unable-to-convert-a-version-class-name-to-a-sem","errorCode":null,"errorMessage":"Unable to convert a #{version.class.name} to a SemVer","messagePattern":"Unable to convert a #(.+?) to a SemVer","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/puppet/pops/types/p_sem_ver_type.rb","lineNumber":53,"sourceCode":"    super ^ @ranges.hash\n  end\n\n  # Creates a SemVer version from the given _version_ argument. If the argument is `nil` or\n  # a {SemanticPuppet::Version}, it is returned. If it is a {String}, it will be parsed into a\n  # {SemanticPuppet::Version}. Any other class will raise an {ArgumentError}.\n  #\n  # @param version [SemanticPuppet::Version,String,nil] the version to convert\n  # @return [SemanticPuppet::Version] the converted version\n  # @raise [ArgumentError] when the argument cannot be converted into a version\n  #\n  def self.convert(version)\n    case version\n    when nil, SemanticPuppet::Version\n      version\n    when String\n      SemanticPuppet::Version.parse(version)\n    else\n      raise ArgumentError, \"Unable to convert a #{version.class.name} to a SemVer\"\n    end\n  end\n\n  # @api private\n  def self.new_function(type)\n    @new_function ||= Puppet::Functions.create_loaded_function(:new_Version, type.loader) do\n      local_types do\n        type 'PositiveInteger = Integer[0,default]'\n        type 'SemVerQualifier = Pattern[/\\A(?<part>[0-9A-Za-z-]+)(?:\\.\\g<part>)*\\Z/]'\n        type \"SemVerPattern = Pattern[/\\\\A#{SemanticPuppet::Version::REGEX_FULL}\\\\Z/]\"\n        type 'SemVerHash = Struct[{major=>PositiveInteger,minor=>PositiveInteger,patch=>PositiveInteger,Optional[prerelease]=>SemVerQualifier,Optional[build]=>SemVerQualifier}]'\n      end\n\n      # Creates a SemVer from a string as specified by http://semver.org/\n      #\n      dispatch :from_string do\n        param 'SemVerPattern', :str\n      end","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/pops/types/p_sem_ver_type.rb#L35-L71","documentation":"PSemVerType.convert normalizes input for the SemVer type: nil and SemanticPuppet::Version pass through, Strings are parsed via SemanticPuppet::Version.parse, and any other class raises ArgumentError stating it cannot be converted to a SemVer. Unlike the new function (which accepts a Struct of parts), convert accepts only these three forms.","triggerScenarios":"Ruby-side: Puppet::Pops::Types::PSemVerType.convert(1.9), convert(:latest), or convert([1,2,3]). DSL-side: SemVer[1] or SemVer[3.2] - a bare number instead of a dotted version String or parts Struct.","commonSituations":"Passing a Float/Integer version (1.9 instead of '1.9.0'); passing a Hash of parts to the Ruby API (allowed by the DSL new function but not convert); version data read from YAML where '1.2.3' lost its quotes and became something else.","solutions":["Pass a full semantic version String: '1.9.0' (three segments; use the DSL new() parts form for programmatic construction)","Or pass an existing SemanticPuppet::Version object; nil is also accepted","Coerce numeric input to String and ensure it has major.minor.patch segments"],"exampleFix":"# before\nPuppet::Pops::Types::PSemVerType.convert(1.9)   # ArgumentError\n$v = SemVer[1]                                   # DSL equivalent\n\n# after\nPuppet::Pops::Types::PSemVerType.convert('1.9.0')\n$v = SemVer['1.9.0']                             # or SemVer({major=>1,minor=>9,patch=>0})","handlingStrategy":"type-guard","validationCode":"# accept only nil, Version, or String before calling convert\nunless version.nil? || version.is_a?(SemanticPuppet::Version) || version.is_a?(String)\n  raise ArgumentError, \"expected a SemVer String or Version, got #{version.class}\"\nend","typeGuard":"def semver_input?(v)\n  v.nil? || v.is_a?(SemanticPuppet::Version) || v.is_a?(String)\nend","tryCatchPattern":"begin\n  Puppet::Pops::Types::PSemVerType.convert(input)\nrescue ArgumentError => e\n  raise unless e.message =~ /to a SemVer/\n  raise \"invalid version #{input.inspect}: pass a String like '1.9.0'\"\nend","preventionTips":["Quote version literals in YAML/JSON data so they stay Strings","Use the parts Struct form (SemVer.new(major:..)) when constructing programmatically"],"tags":["puppet","semver","type-conversion","ruby"],"backgroundTag":"version-parse-error","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}