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.
Solutions
- Add "branches" and/or "lines" thresholds to the nyc/c8 config in package.json or .nycrc.
- Or pass preferredThreshold=functions along with a `functions` threshold in the config.
- 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
- Always set explicit branches and lines thresholds in .nycrc or package.json
- Don't rely on implicit coverage defaults when publishing coverage badges
- If you only track functions coverage, pass the preferredThreshold parameter explicitly
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
- no nyc or c8 stanza found
- " " threshold missing
- coverage not found
- invalid url parameter
- no coverage data available
AI-assisted analysis of badges/shields@766fd8bc89 (2026-08-30).
Data as JSON: /api/errors/6bc7d41e07f8e005.
Report an issue: GitHub.
Appendix: 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)