badges/shields · error · InvalidResponse

"branches" or "lines" threshold missing

Error message

"branches" or "lines" threshold missing

What it means

When no preferredThreshold is supplied, the nycrc service falls back to the branches threshold (or lines if branches is absent). If the parsed config contains neither a `branches` nor a `lines` entry, it throws InvalidResponse with this message because there is no coverage threshold to render.

Source

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

    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',
      })
    }
  }

  async handle({ user, repo }, queryParams) {
    const { config, preferredThreshold } = queryParams
    let coverage
    if (config.includes('package.json')) {
      const pkgJson = await fetchJsonFromRepo(this, {
        schema: pkgJSONSchema,
        user,
        repo,
        branch: 'HEAD',
        filename: config,
      })
      const nycConfig = pkgJson.c8 || pkgJson.nyc
      if (!nycConfig) {

View on GitHub (pinned to 766fd8bc89)

Solutions

  1. Add "branches" and/or "lines" thresholds to the nyc/c8 config in package.json or .nycrc.
  2. Or pass preferredThreshold=functions along with a `functions` threshold in the config.
  3. Verify the config file being fetched (the `config` filename param) is the one actually holding the thresholds.

Example fix

// before (.nycrc)
{ "check-coverage": true }
// after
{ "check-coverage": true, "branches": 80, "lines": 90 }
Defensive patterns

Strategy: validation

Validate before calling

const cfg = pkg.nyc || pkg.c8 || {}
if (!cfg.branches && !cfg.lines && !preferredThreshold) {
  throw new Error('Define branches or lines thresholds, or pass preferredThreshold')
}

Type guard

function hasFallbackThreshold(cfg) {
  return Boolean(cfg && (cfg.branches || cfg.lines))
}

Prevention

When it happens

Trigger: Requesting the nycrc badge without a preferredThreshold while the project's nyc/c8 config defines neither `branches` nor `lines` (e.g. only `functions` or only `check-coverage: true` with per-file settings).

Common situations: Minimal .nycrc files that only configure include/exclude patterns; configs relying on defaults without explicit thresholds; misplacing the nyc stanza so the parsed config lacks threshold keys.

Related errors


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