badges/shields · error · Error

Unknown releaseType: ${releaseType}

Error message

Unknown releaseType: ${releaseType}

What it means

slice() in services/version.js truncates a parsed version to the requested release level. It looks up the releaseType in a map of 'major' | 'minor' | 'patch' to dotted parts; if releaseType is anything else the lookup is undefined and the function throws this plain Error. It guards against unsupported granularity values passed by callers such as capitalize, format, coalesceBadge and extension.

Source

Thrown at services/version.js:199

 */
function slice(v, releaseType) {
  if (!semver.valid(v, /* loose */ true)) {
    return null
  }

  const major = semver.major(v, /* loose */ true)
  const minor = semver.minor(v, /* loose */ true)
  const patch = semver.patch(v, /* loose */ true)
  const prerelease = semver.prerelease(v, /* loose */ true)

  const dottedParts = {
    major: [major],
    minor: [major, minor],
    patch: [major, minor, patch],
  }[releaseType]

  if (dottedParts === undefined) {
    throw Error(`Unknown releaseType: ${releaseType}`)
  }

  const dotted = dottedParts.join('.')
  if (prerelease) {
    return `${dotted}-${prerelease.join('.')}`
  } else {
    return dotted
  }
}

/**
 * Returns the start of the range that matches a given version string.
 *
 * @param {string} v - A version string that follows the Semantic Versioning specification. The function will accept and coerce invalid versions into valid ones.
 * @returns {string} The start of the range that matches the given version string, or null if no match is found.
 * @throws {TypeError} If v is an invalid semver range
 * @example
 * rangeStart('^1.2.3') // returns '1.2.3'

View on GitHub (pinned to 766fd8bc89)

Solutions

  1. Fix the caller to pass exactly 'major', 'minor' or 'patch'
  2. Validate/normalize the user- or route-supplied releaseType before calling slice (whitelist check, lowercase trim)
  3. If other granularities are needed, add them to the { major: [...], minor: [...], patch: [...] } map

Example fix

// before
const sliced = slice(version, 'semver')
// after
const sliced = slice(version, 'patch')
Defensive patterns

Strategy: type-guard

Validate before calling

const RELEASE_TYPES = ['major', 'minor', 'patch']
if (!RELEASE_TYPES.includes(releaseType)) {
  throw new Error(`Invalid releaseType: ${releaseType}`)
}

Type guard

function isReleaseType(v) {
  return v === 'major' || v === 'minor' || v === 'patch'
}

Try / catch

try {
  return slice(version, releaseType)
} catch (err) {
  if (err.message.startsWith('Unknown releaseType:')) {
    return version // fall back to the full version string
  }
  throw err
}

Prevention

When it happens

Trigger: Calling slice(version, releaseType) with a value other than 'major', 'minor', or 'patch' — e.g. 'build', 'prerelease', an empty string, or a user-provided granularity from a service config or route parameter.

Common situations: A badge/service config exposes 'which parts of the version to show' to users and a bad value ('full', 'semver') is forwarded; a typo in a route parameter; a new releaseType added in one place but not to slice's map.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of badges/shields@766fd8bc89 (2026-08-30). Data as JSON: /api/errors/a774b2fd1d4debf8. Report an issue: GitHub.