{"record":{"id":"6bc7d41e07f8e005","repo":"badges/shields","slug":"branches-or-lines-threshold-missing","errorCode":null,"errorMessage":"\"branches\" or \"lines\" threshold missing","messagePattern":"\"branches\" or \"lines\" threshold missing","errorType":"exception","errorClass":"InvalidResponse","httpStatus":null,"severity":"error","filePath":"services/nycrc/nycrc.service.js","lineNumber":105,"sourceCode":"    if (preferredThreshold) {\n      if (!validThresholds.includes(preferredThreshold)) {\n        throw new InvalidParameter({\n          prettyMessage:\n            'threshold must be \"branches\", \"lines\", or \"functions\"',\n        })\n      }\n      if (!config[preferredThreshold]) {\n        throw new InvalidResponse({\n          prettyMessage: `\"${preferredThreshold}\" threshold missing`,\n        })\n      }\n      return config[preferredThreshold]\n    } else if (branches || lines) {\n      // We favor branches over lines for the coverage badge, if both\n      // thresholds are provided (as branches is the stricter requirement):\n      return branches || lines\n    } else {\n      throw new InvalidResponse({\n        prettyMessage: '\"branches\" or \"lines\" threshold missing',\n      })\n    }\n  }\n\n  async handle({ user, repo }, queryParams) {\n    const { config, preferredThreshold } = queryParams\n    let coverage\n    if (config.includes('package.json')) {\n      const pkgJson = await fetchJsonFromRepo(this, {\n        schema: pkgJSONSchema,\n        user,\n        repo,\n        branch: 'HEAD',\n        filename: config,\n      })\n      const nycConfig = pkgJson.c8 || pkgJson.nyc\n      if (!nycConfig) {","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/badges/shields/blob/766fd8bc89a90b8534dc573ab72dec30215ab1ec/services/nycrc/nycrc.service.js#L87-L123","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"// before (.nycrc)\n{ \"check-coverage\": true }\n// after\n{ \"check-coverage\": true, \"branches\": 80, \"lines\": 90 }","handlingStrategy":"validation","validationCode":"const cfg = pkg.nyc || pkg.c8 || {}\nif (!cfg.branches && !cfg.lines && !preferredThreshold) {\n  throw new Error('Define branches or lines thresholds, or pass preferredThreshold')\n}","typeGuard":"function hasFallbackThreshold(cfg) {\n  return Boolean(cfg && (cfg.branches || cfg.lines))\n}","tryCatchPattern":null,"preventionTips":["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"],"tags":["config","coverage","missing-key"],"backgroundTag":"missing-config-key","analyzedSha":"766fd8bc89a90b8534dc573ab72dec30215ab1ec","analyzedAt":"2026-08-30T01:40:27.499Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}