{"record":{"id":"4d0c946842b3285f","repo":"affaan-m/ECC","slug":"label-must-be-one-of-allowed-join","errorCode":null,"errorMessage":"${label} must be one of: ${allowed.join(', ')}.","messagePattern":"(.+?) must be one of: (.+?)\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"scripts/lib/memory-vault-format.js","lineNumber":94,"sourceCode":"\nfunction asNonEmptyString(value, label, maxChars = 10_000) {\n  if (typeof value !== 'string' || value.trim().length === 0) {\n    throw new Error(`${label} must be a non-empty string.`);\n  }\n  const normalized = value.trim();\n  if (normalized.length > maxChars) {\n    throw new Error(`${label} is too long (maximum ${maxChars} characters).`);\n  }\n  if (hasUnsafeControlCharacters(normalized)) {\n    throw new Error(`${label} must not contain control or bidirectional formatting characters.`);\n  }\n  return normalized;\n}\n\nfunction validateEnum(value, allowed, label) {\n  const normalized = asNonEmptyString(value, label, 64);\n  if (!allowed.includes(normalized)) {\n    throw new Error(`${label} must be one of: ${allowed.join(', ')}.`);\n  }\n  return normalized;\n}\n\nfunction validateSlug(value, label) {\n  const normalized = asNonEmptyString(value, label, 64);\n  if (!SLUG_PATTERN.test(normalized)) {\n    throw new Error(`${label} must be a lowercase letters/numbers slug.`);\n  }\n  return normalized;\n}\n\nfunction validateMemoryId(value) {\n  const normalized = asNonEmptyString(value, 'memory id', 132);\n  if (!MEMORY_ID_PATTERN.test(normalized)) {\n    throw new Error('memory id must match mem_<lowercase-id> and cannot contain a path.');\n  }\n  return normalized;","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/scripts/lib/memory-vault-format.js#L76-L112","documentation":"validateEnum constrains a field to a fixed set of allowed values (via asNonEmptyString first, cap 64 chars). If the normalized value is not found in the allowed array, the error lists the accepted values, e.g. 'trust must be one of: public, untrusted.'","triggerScenarios":"Calling validateEnum(value, allowed, label) (directly or via normalizeMemory for scopes/kinds/trust) with a value outside the allowed list — typos, different casing, or a value from an older schema version.","commonSituations":"Writing 'Trust: public' or 'PUBLIC' instead of lowercase 'public'; a kind renamed in a newer vault version; hardcoding a scope string that drifted from the canonical list; importing records from another tool with different vocab.","solutions":["Use exactly one of the values listed in the error message, matching case.","Import/export canonical values from the library's constants rather than hardcoding strings.","Normalize the value (lowercase/trim) before validating.","Migrate old records whose enum vocabulary predates the current version."],"exampleFix":"// before\nvalidateEnum('Public', ['public', 'untrusted'], 'trust')\n// after\nvalidateEnum('public', ['public', 'untrusted'], 'trust')","handlingStrategy":"validation","validationCode":"const TRUST_LEVELS = ['public', 'untrusted']\nif (!TRUST_LEVELS.includes(String(raw.trust ?? '').toLowerCase())) {\n  throw new Error(`trust must be one of: ${TRUST_LEVELS.join(', ')}`)\n}","typeGuard":"function isAllowedEnum(v, allowed) {\n  return typeof v === 'string' && allowed.includes(v.trim())\n}\nif (!isAllowedEnum(input.trust, ['public', 'untrusted'])) throw new TypeError('trust has an invalid value')","tryCatchPattern":"try {\n  const memory = normalizeMemory(raw)\n} catch (err) {\n  if (err.message.includes('must be one of')) {\n    console.error(err.message) // message lists the allowed values\n  } else throw err\n}","preventionTips":["Copy enum values from the library's exported constants, never hand-type them.","Match casing exactly (enums are case-sensitive after trim).","Normalize inputs (trim/lowercase) before validating.","Migrate records when enum vocabularies change between versions."],"tags":["validation","memory-vault","enum"],"backgroundTag":"invalid-enum-value","analyzedSha":"8321021c54d670126ce3b2969d5deb880b4b0c2a","analyzedAt":"2026-09-16T10:08:13.343Z","contentChangedAt":"2026-09-16T10:08:13.343Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}