{"record":{"id":"8f6eb2734a2dedb9","repo":"badges/shields","slug":"preferredthreshold-threshold-missing","errorCode":null,"errorMessage":"\"${preferredThreshold}\" threshold missing","messagePattern":"\"(.+?)\" threshold missing","errorType":"exception","errorClass":"InvalidResponse","httpStatus":null,"severity":"error","filePath":"services/nycrc/nycrc.service.js","lineNumber":95,"sourceCode":"\n  static render({ coverage }) {\n    return {\n      message: `${coverage.toFixed(0)}%`,\n      color: coveragePercentage(coverage),\n    }\n  }\n\n  extractThreshold(config, preferredThreshold) {\n    const { branches, lines } = config\n    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","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/badges/shields/blob/766fd8bc89a90b8534dc573ab72dec30215ab1ec/services/nycrc/nycrc.service.js#L77-L113","documentation":"When a valid preferredThreshold is given, the nycrc service looks up that key (branches/lines/functions) in the parsed nyc/c8 config and throws InvalidResponse if the key is absent or falsy. This means the user's package.json or .nycrc does not define the threshold they explicitly asked the badge to display.","triggerScenarios":"Badge request specifies e.g. preferred_threshold=functions, but the project's nyc/c8 stanza has no `functions` threshold configured (`!config[preferredThreshold]` is true).","commonSituations":"Configs that only set `lines`/`branches` thresholds while the badge asks for `functions`; thresholds set to 0 or omitted in package.json `nyc` block; switching badge param without updating .nycrc.","solutions":["Add the requested threshold key (e.g. \"functions\": 80) to the nyc/c8 config in package.json or .nycrc.","Or change the badge's preferredThreshold parameter to a threshold the config actually defines.","Ensure the threshold value is non-zero, since a falsy value also triggers this error."],"exampleFix":"// before (package.json)\n\"nyc\": { \"lines\": 90 }\n// after\n\"nyc\": { \"lines\": 90, \"functions\": 85 }","handlingStrategy":"validation","validationCode":"const cfg = require('./package.json').nyc || require('./package.json').c8\nif (!cfg || !cfg[preferredThreshold]) {\n  throw new Error(`Config does not define a ${preferredThreshold} threshold`)\n}","typeGuard":"function hasThreshold(cfg, key) {\n  return cfg != null && typeof cfg === 'object' &&\n    typeof cfg[key] === 'number' && cfg[key] > 0\n}","tryCatchPattern":null,"preventionTips":["Keep every threshold you badge (branches/lines/functions) defined in the nyc/c8 stanza","Avoid threshold values of 0, which are falsy and trigger the error","Run a quick JSON sanity check on the config file after editing it"],"tags":["config","coverage","missing-key","validation"],"backgroundTag":"missing-config-key","analyzedSha":"766fd8bc89a90b8534dc573ab72dec30215ab1ec","analyzedAt":"2026-08-30T01:40:27.499Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}