{"record":{"id":"9a227e902ddc5aac","repo":"badges/shields","slug":"field-links-must-not-have-more-than-2-elements","errorCode":null,"errorMessage":"Field `links` must not have more than 2 elements","messagePattern":"Field `links` must not have more than 2 elements","errorType":"validation","errorClass":"ValidationError","httpStatus":null,"severity":"error","filePath":"badge-maker/lib/index.js","lineNumber":30,"sourceCode":"  }\n\n  if (!('message' in format)) {\n    throw new ValidationError('Field `message` is required')\n  }\n\n  const stringFields = ['labelColor', 'color', 'message', 'label', 'logoBase64']\n  stringFields.forEach(function (field) {\n    if (field in format && typeof format[field] !== 'string') {\n      throw new ValidationError(`Field \\`${field}\\` must be of type string`)\n    }\n  })\n\n  if ('links' in format) {\n    if (!Array.isArray(format.links)) {\n      throw new ValidationError('Field `links` must be an array of strings')\n    } else {\n      if (format.links.length > 2) {\n        throw new ValidationError(\n          'Field `links` must not have more than 2 elements',\n        )\n      }\n      format.links.forEach(function (field) {\n        if (typeof field !== 'string') {\n          throw new ValidationError('Field `links` must be an array of strings')\n        }\n      })\n    }\n  }\n\n  const styleValues = [\n    'plastic',\n    'flat',\n    'flat-square',\n    'for-the-badge',\n    'social',\n  ]","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/badges/shields/blob/766fd8bc89a90b8534dc573ab72dec30215ab1ec/badge-maker/lib/index.js#L12-L48","documentation":"The `links` array may contain at most 2 URLs — the left and right halves of the badge each get at most one link. _validate checks format.links.length > 2 (badge-maker/lib/index.js:29) and throws when more are supplied. This is a hard library limit on clickable regions, not an arbitrary array cap.","triggerScenarios":"makeBadge({ message: 'x', links: ['https://a.com', 'https://b.com', 'https://c.com'] }) — three or more URLs in the links array.","commonSituations":"Trying to attach one link per badge segment or forwarding all project URLs (homepage, docs, repo, issues) into links; bulk-generating badges from a config where a links list grew over time.","solutions":["Truncate the array to two entries before calling: links: myLinks.slice(0, 2)","Split content across multiple badges if you need more than two linked areas","Keep only the two most important links and render the rest as separate badges"],"exampleFix":"// before\nconst svg = makeBadge({ message: 'project', links: [home, docs, repo] })\n// after\nconst svg = makeBadge({ message: 'project', links: [home, docs].slice(0, 2) })","handlingStrategy":"validation","validationCode":"if (badge.links && badge.links.length > 2) {\n  badge.links = badge.links.slice(0, 2)\n}\nconst svg = makeBadge(badge)","typeGuard":null,"tryCatchPattern":"try {\n  return makeBadge(badge)\n} catch (e) {\n  if (e instanceof ValidationError && e.message.includes('more than 2 elements')) {\n    return makeBadge({ ...badge, links: badge.links.slice(0, 2) })\n  }\n  throw e\n}","preventionTips":["Remember a badge supports at most 2 clickable areas (left/right halves)","Render additional links as separate badges","Cap link lists when building descriptors from config"],"tags":["validation","array-length","limits"],"backgroundTag":"array-length-exceeded","analyzedSha":"766fd8bc89a90b8534dc573ab72dec30215ab1ec","analyzedAt":"2026-08-30T01:40:27.499Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}