badges/shields · error · ValidationError
Field `message` is required
Error message
Field `message` is required
What it means
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.
Source
Thrown at badge-maker/lib/index.js:15
/**
* @module badge-maker
*/
import _makeBadge from './make-badge.js'
export class ValidationError extends Error {}
function _validate(format) {
if (format !== Object(format)) {
throw new ValidationError('makeBadge takes an argument of type object')
}
if (!('message' in format)) {
throw new ValidationError('Field `message` is required')
}
const stringFields = ['labelColor', 'color', 'message', 'label', 'logoBase64']
stringFields.forEach(function (field) {
if (field in format && typeof format[field] !== 'string') {
throw new ValidationError(`Field \`${field}\` must be of type string`)
}
})
if ('links' in format) {
if (!Array.isArray(format.links)) {
throw new ValidationError('Field `links` must be an array of strings')
} else {
if (format.links.length > 2) {
throw new ValidationError(
'Field `links` must not have more than 2 elements',
)
}View on GitHub (pinned to 766fd8bc89)
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'
Example fix
// before
const svg = makeBadge({ label: 'build' })
// after
const svg = makeBadge({ label: 'build', message: 'passing' }) Defensive patterns
Strategy: validation
Validate before calling
if (!('message' in badge)) {
throw new Error('badge descriptor requires `message`')
}
const svg = makeBadge(badge) Type guard
function hasMessage(v) {
return typeof v === 'object' && v !== null && 'message' in v
} Try / catch
try {
return makeBadge(badge)
} catch (e) {
if (e instanceof ValidationError && e.message === 'Field `message` is required') {
return makeBadge({ ...badge, message: 'unknown' })
}
throw e
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "Missing required field" and "field is required" errors: why libraries reject payloads that omit mandatory fields — this error's family across 20 libraries.
Related errors
- makeBadge takes an argument of type object
- Field `${field}` must be of type string
- Field `links` must be an array of strings
- Field `links` must not have more than 2 elements
- Field `style` must be one of (${styleValues.toString()})
AI-assisted analysis of badges/shields@766fd8bc89 (2026-08-30).
Data as JSON: /api/errors/5cb8e053a1bbb507.
Report an issue: GitHub.