{"record":{"id":"5cb8e053a1bbb507","repo":"badges/shields","slug":"field-message-is-required","errorCode":null,"errorMessage":"Field `message` is required","messagePattern":"Field `message` is required","errorType":"validation","errorClass":"ValidationError","httpStatus":null,"severity":"error","filePath":"badge-maker/lib/index.js","lineNumber":15,"sourceCode":"/**\n * @module badge-maker\n */\n\nimport _makeBadge from './make-badge.js'\n\nexport class ValidationError extends Error {}\n\nfunction _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      }","sourceCodeStart":1,"sourceCodeEnd":33,"githubUrl":"https://github.com/badges/shields/blob/766fd8bc89a90b8534dc573ab72dec30215ab1ec/badge-maker/lib/index.js#L1-L33","documentation":"The `message` field is the only required property of the badge descriptor. _validate checks `'message' in format` (badge-maker/lib/index.js:14) and throws when it is absent, because a badge without message text cannot be rendered meaningfully. `label` is optional (defaults to empty string), but `message` is not.","triggerScenarios":"makeBadge({ label: 'build' }), makeBadge({ color: '#4c1', style: 'flat' }), or makeBadge({ message: undefined }) — any call whose options object omits a `message` key. Note `'message' in format` is true even if the value is null/undefined but the key exists.","commonSituations":"Building the options object dynamically (e.g. spreading config) where the message value comes from a CI variable that is empty and the key is omitted; migrating from APIs where message was optional; copy-pasting examples and deleting the wrong line.","solutions":["Add the required message field: makeBadge({ message: 'passing' })","Ensure the message key exists even if empty — note the key must be present; a null message key passes this check but is dropped by _clean","If the message comes from an upstream variable, default it: message: statusText ?? 'unknown'"],"exampleFix":"// before\nconst svg = makeBadge({ label: 'build' })\n// after\nconst svg = makeBadge({ label: 'build', message: 'passing' })","handlingStrategy":"validation","validationCode":"if (!('message' in badge)) {\n  throw new Error('badge descriptor requires `message`')\n}\nconst svg = makeBadge(badge)","typeGuard":"function hasMessage(v) {\n  return typeof v === 'object' && v !== null && 'message' in v\n}","tryCatchPattern":"try {\n  return makeBadge(badge)\n} catch (e) {\n  if (e instanceof ValidationError && e.message === 'Field `message` is required') {\n    return makeBadge({ ...badge, message: 'unknown' })\n  }\n  throw e\n}","preventionTips":["Always set message in generated descriptors, even as a placeholder","Default upstream values: message: ciStatus ?? 'unknown'","Write a unit test asserting every badge descriptor your app builds has message"],"tags":["validation","missing-field","required-argument"],"backgroundTag":"missing-required-field","analyzedSha":"766fd8bc89a90b8534dc573ab72dec30215ab1ec","analyzedAt":"2026-08-30T01:40:27.499Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}