{"record":{"id":"29d438c331b5e352","repo":"badges/shields","slug":"field-links-must-be-an-array-of-strings","errorCode":null,"errorMessage":"Field `links` must be an array of strings","messagePattern":"Field `links` must be an array of strings","errorType":"validation","errorClass":"ValidationError","httpStatus":null,"severity":"error","filePath":"badge-maker/lib/index.js","lineNumber":27,"sourceCode":"function _validate(format) {\n  if (format !== Object(format)) {\n    throw new ValidationError('makeBadge takes an argument of type object')\n  }\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',","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/badges/shields/blob/766fd8bc89a90b8534dc573ab72dec30215ab1ec/badge-maker/lib/index.js#L9-L45","documentation":"When the optional `links` field is provided it must be an array. _validate checks Array.isArray(format.links) (badge-maker/lib/index.js:26) and throws this ValidationError if links is a string, object, or any non-array value. This is the not-an-array branch of the links validation.","triggerScenarios":"makeBadge({ message: 'docs', links: 'https://example.com' }) — a single URL string instead of an array; also links: {} or links: 5. Any truthy links value that fails Array.isArray.","commonSituations":"Passing one link as a bare string because a single link 'obviously' doesn't need an array; deserializing config from YAML/TOML where a single-element link becomes a scalar; a template variable that is sometimes a string and sometimes an array.","solutions":["Wrap the link in an array: links: ['https://example.com']","Normalize before calling: links: Array.isArray(link) ? link : [link]","Omit the links field entirely if you have no links (undefined/null keys are dropped by _clean)"],"exampleFix":"// before\nconst svg = makeBadge({ message: 'docs', links: 'https://example.com' })\n// after\nconst svg = makeBadge({ message: 'docs', links: ['https://example.com'] })","handlingStrategy":"type-guard","validationCode":"if ('links' in badge && !Array.isArray(badge.links)) {\n  badge.links = [badge.links]\n}\nconst svg = makeBadge(badge)","typeGuard":"function isStringArray(v) {\n  return Array.isArray(v) && v.every(x => typeof x === 'string')\n}","tryCatchPattern":"try {\n  return makeBadge(badge)\n} catch (e) {\n  if (e instanceof ValidationError && e.message.includes('`links`')) {\n    return makeBadge({ ...badge, links: [].concat(badge.links).filter(l => typeof l === 'string') })\n  }\n  throw e\n}","preventionTips":["Always pass links as an array, even for a single URL","Normalize scalar-or-array inputs at config load: [].concat(maybeLink)","Add a schema check (e.g. zod) on the badge descriptor"],"tags":["validation","type-mismatch","array"],"backgroundTag":"invalid-field-type","analyzedSha":"766fd8bc89a90b8534dc573ab72dec30215ab1ec","analyzedAt":"2026-08-30T01:40:27.499Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}