{"record":{"id":"09b553013bc588a1","repo":"affaan-m/ECC","slug":"label-is-too-long-maximum-maxchars-characte","errorCode":null,"errorMessage":"${label} is too long (maximum ${maxChars} characters).","messagePattern":"(.+?) is too long \\(maximum (.+?) characters\\)\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"scripts/lib/memory-vault-format.js","lineNumber":83,"sourceCode":"    const allowedWhitespace = allowBodyWhitespace\n      && (codePoint === 0x09 || codePoint === 0x0a || codePoint === 0x0d);\n    const isControl = (codePoint <= 0x1f && !allowedWhitespace)\n      || (codePoint >= 0x7f && codePoint <= 0x9f);\n    const isBidirectionalFormatting = (\n      (codePoint >= 0x202a && codePoint <= 0x202e)\n      || (codePoint >= 0x2066 && codePoint <= 0x2069)\n    );\n    return isControl || isBidirectionalFormatting;\n  });\n}\n\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)) {","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/scripts/lib/memory-vault-format.js#L65-L101","documentation":"asNonEmptyString enforces a maximum length (default 10,000 chars; 64 for labels/enums/slugs) on validated strings to keep memory-vault records small and safe. Values that are valid strings but exceed the cap are rejected with the label and the limit in the message.","triggerScenarios":"Calling asNonEmptyString with a string whose trimmed length exceeds maxChars — e.g. pasting a multi-KB document into a title field, or a 65+ char label/slug via validateEnum/validateSlug.","commonSituations":"Storing an entire article body where only a summary belongs; unbounded user input from a textarea; generated slugs not truncated; test fixtures with very long strings.","solutions":["Truncate the input to maxChars before validation (mind surrogate pairs).","Use a field sized for the content (e.g. a body/description field with a higher cap) instead of a short label field.","Summarize or compress large content before saving to the vault.","Reduce the content in the source document or split it across records."],"exampleFix":"// before\nasNonEmptyString(longArticle, 'title')  // throws if > 10000 chars\n// after\nasNonEmptyString(longArticle.slice(0, 10000), 'title')","handlingStrategy":"validation","validationCode":"const MAX = 10000\nif (typeof value === 'string' && value.trim().length > MAX) {\n  value = Array.from(value.trim()).slice(0, MAX).join('')\n}","typeGuard":"function isWithinLength(v, max = 10000) {\n  return typeof v === 'string' && v.trim().length <= max\n}\nif (!isWithinLength(input.content)) throw new RangeError('content exceeds 10000 characters')","tryCatchPattern":"try {\n  asNonEmptyString(value, 'content')\n} catch (err) {\n  if (err.message.includes('is too long')) {\n    const max = Number(err.message.match(/maximum (\\d+)/)?.[1] ?? 10000)\n    value = value.trim().slice(0, max)\n  } else throw err\n}","preventionTips":["Truncate long user input at the boundary before saving.","Use the appropriate field for large content (body vs title).","Truncate by code points (Array.from) to avoid splitting surrogate pairs.","Cap textarea maxlength / CLI input length in the UI."],"tags":["validation","memory-vault","size-limit"],"backgroundTag":"value-out-of-range","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"}