badges/shields · error · InvalidParameter

threshold must be "branches", "lines", or "functions"

Error message

threshold must be "branches", "lines", or "functions"

What it means

The nyc/c8 coverage service accepts an optional `preferredThreshold` query parameter to choose which coverage metric to badge. When that parameter is supplied but is not one of "branches", "lines", or "functions" (validThresholds), the service throws InvalidParameter with this message. It is a caller-input validation error, not an upstream-data error.

Source

Thrown at services/nycrc/nycrc.service.js:89

        ],
      },
    },
  }

  static defaultBadgeData = { label: 'min coverage' }

  static render({ coverage }) {
    return {
      message: `${coverage.toFixed(0)}%`,
      color: coveragePercentage(coverage),
    }
  }

  extractThreshold(config, preferredThreshold) {
    const { branches, lines } = config
    if (preferredThreshold) {
      if (!validThresholds.includes(preferredThreshold)) {
        throw new InvalidParameter({
          prettyMessage:
            'threshold must be "branches", "lines", or "functions"',
        })
      }
      if (!config[preferredThreshold]) {
        throw new InvalidResponse({
          prettyMessage: `"${preferredThreshold}" threshold missing`,
        })
      }
      return config[preferredThreshold]
    } else if (branches || lines) {
      // We favor branches over lines for the coverage badge, if both
      // thresholds are provided (as branches is the stricter requirement):
      return branches || lines
    } else {
      throw new InvalidResponse({
        prettyMessage: '"branches" or "lines" threshold missing',
      })

View on GitHub (pinned to 766fd8bc89)

Solutions

  1. Change the preferredThreshold query parameter to one of: branches, lines, or functions.
  2. Omit the parameter entirely to let the service pick branches over lines automatically.
  3. Check spelling and casing of the parameter value in the badge URL.

Example fix

// before
<img src=".../nycrc?preferred_threshold=statements">
// after
<img src=".../nycrc?preferred_threshold=lines">
Defensive patterns

Strategy: validation

Validate before calling

const VALID = ['branches', 'lines', 'functions']
if (preferredThreshold && !VALID.includes(preferredThreshold)) {
  throw new Error(`preferredThreshold must be one of ${VALID.join(', ')}`)
}

Type guard

function isValidThreshold(t) {
  return t === undefined || ['branches', 'lines', 'functions'].includes(t)
}

Prevention

When it happens

Trigger: Requesting an nycrc badge with a `preferred_threshold` (or equivalent query param) set to anything outside {branches, lines, functions}, e.g. `statements` or `coverage`.

Common situations: Users copying a threshold name from their nyc config that nyc supports but this badge does not (like `statements` or `lines` misspelled as `line`), or passing the config key with wrong casing.

Understand the failure class

Background: "must be positive", "Invalid value": how libraries reject invalid parameter values (ValueError, ArgumentError, INVALID_PARAMETER_VALUE) — this error's family across 28 libraries.

Related errors


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