{"record":{"id":"86ddd6656eccf92b","repo":"puppetlabs/puppet","slug":"unable-to-parse-ver-as-a-debian-version-ident","errorCode":null,"errorMessage":"Unable to parse '#{ver}' as a debian version identifier","messagePattern":"Unable to parse '#(.+?)' as a debian version identifier","errorType":"validation","errorClass":"ValidationFailure","httpStatus":null,"severity":"error","filePath":"lib/puppet/util/package/version/debian.rb","lineNumber":24,"sourceCode":"\n    # Version string matching regexes\n    REGEX_EPOCH = '(?:([0-9]+):)?'\n    # alphanumerics and the characters . + - ~ , starts with a digit, ~ only of debian_revision is present\n    REGEX_UPSTREAM_VERSION = '([\\.\\+~0-9a-zA-Z-]+?)'\n    # alphanumerics and the characters + . ~\n    REGEX_DEBIAN_REVISION = '(?:-([\\.\\+~0-9a-zA-Z]*))?'\n\n    REGEX_FULL    = REGEX_EPOCH + REGEX_UPSTREAM_VERSION + REGEX_DEBIAN_REVISION.freeze\n    REGEX_FULL_RX = /\\A#{REGEX_FULL}\\Z/\n\n    class ValidationFailure < ArgumentError; end\n\n    def self.parse(ver)\n      raise ValidationFailure, \"Unable to parse '#{ver}' as a string\" unless ver.is_a?(String)\n\n      match, epoch, upstream_version, debian_revision = *ver.match(REGEX_FULL_RX)\n\n      raise ValidationFailure, \"Unable to parse '#{ver}' as a debian version identifier\" unless match\n\n      new(epoch.to_i, upstream_version, debian_revision).freeze\n    end\n\n    def to_s\n      s = @upstream_version\n      s = \"#{@epoch}:#{s}\" if @epoch != 0\n      s = \"#{s}-#{@debian_revision}\" if @debian_revision\n      s\n    end\n    alias inspect to_s\n\n    def eql?(other)\n      other.is_a?(self.class) &&\n        @epoch.eql?(other.epoch) &&\n        @upstream_version.eql?(other.upstream_version) &&\n        @debian_revision.eql?(other.debian_revision)\n    end","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/util/package/version/debian.rb#L6-L42","documentation":"Raised by Puppet::Util::Package::Version::Debian.parse when the input String does not fully match the Debian version grammar REGEX_FULL_RX = /\\A(?:([0-9]+):)?([.+~0-9a-zA-Z-]+?)(?:-([.+~0-9a-zA-Z]*))?\\Z/ (epoch:upstream-version with optional -debian-revision). ValidationFailure subclasses ArgumentError, so it is catchable as ArgumentError. Any character outside [0-9a-zA-Z.+~-], an empty upstream part, surrounding whitespace, or a stray ':' causes the match (and thus the parse) to fail.","triggerScenarios":"Calling Debian.parse with: '1.0_beta' or '1.0 beta' (underscore/space not in the character class), '' (upstream part is +? so at least one char required), ' 1.0' (leading whitespace, anchored \\A), '1:2.3:4' (second colon cannot match), '1.0~rc1-x's are fine but '1..2.3!' is not. Passing a non-String (Integer, Symbol, nil) hits the separate 'as a string' raise at debian.rb:20 instead.","commonSituations":"Puppet package resources whose ensure is a version string copied from upstream release tags ('v1.2.3' is actually parseable since 'v' is alphanumeric, but '1.2.3-rc1+b1!' style strings from GitHub releases are not); versions read from YAML/JSON data files that carry whitespace or newlines; feeding RPM-style '1:1.2.3-4.el7' with extra revision chars, or pip-style '1.0.post1' containing characters Debian allows only in certain positions.","solutions":["Normalize the string before parsing: strip whitespace, drop a leading 'v', and reject empty strings.","Pre-validate against Puppet::Util::Package::Version::Debian::REGEX_FULL_RX (match with \\A/\\Z anchoring) and skip or fallback when it does not match.","Rescue Puppet::Util::Package::Version::Debian::ValidationFailure (an ArgumentError) at the call site and degrade to a plain version string or installed/latest.","Check the value against Debian policy: optional numeric epoch + ':', upstream version of [0-9a-zA-Z.+~-], optional '-' + revision of [0-9a-zA-Z.+~]."],"exampleFix":"// before\nver = Puppet::Util::Package::Version::Debian.parse(pkg_version) # raises on '1.0 beta'\n\n// after\ndef parse_debian_safe(str)\n  return nil unless str.is_a?(String)\n  return nil unless str =~ /\\A(?:([0-9]+):)?([.+~0-9a-zA-Z-]+?)(?:-([.+~0-9a-zA-Z]*))?\\Z/\n  Puppet::Util::Package::Version::Debian.parse(str)\nend\nver = parse_debian_safe(pkg_version.strip.sub(/\\Av/, '')) || fallback","handlingStrategy":"validation","validationCode":"def parseable_debian?(str)\n  str.is_a?(String) && str.match?(Puppet::Util::Package::Version::Debian::REGEX_FULL_RX)\nend\n\nver = parseable_debian?(candidate) ? Puppet::Util::Package::Version::Debian.parse(candidate.strip) : nil","typeGuard":null,"tryCatchPattern":"begin\n  ver = Puppet::Util::Package::Version::Debian.parse(candidate)\nrescue Puppet::Util::Package::Version::Debian::ValidationFailure => e\n  Puppet.err(\"invalid debian version #{candidate.inspect}: #{e.message}\")\n  ver = nil\nend","preventionTips":["Strip whitespace and drop a leading 'v' before parsing version strings from external data.","Validate against Debian::REGEX_FULL_RX before parse when input comes from manifests or data bindings.","Treat the ensure value 'installed'/'latest' as non-version input and never route it to version parsers."],"tags":["puppet","debian","package-version","version-parsing","argumenterror","validation"],"backgroundTag":"package-version-parse-failed","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}