{"record":{"id":"1e7703a81d0ee130","repo":"affaan-m/ECC","slug":"memory-body-must-contain-non-whitespace-context","errorCode":null,"errorMessage":"memory body must contain non-whitespace context.","messagePattern":"memory body must contain non-whitespace context\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/lib/memory-vault-format.js","lineNumber":153,"sourceCode":"    !ISO_TIMESTAMP_PATTERN.test(normalized)\n    || Number.isNaN(parsed.getTime())\n    || parsed.toISOString() !== normalized\n  ) {\n    throw new Error(`${label} must be an ISO-8601 timestamp.`);\n  }\n  return normalized;\n}\n\nfunction normalizeBody(value) {\n  if (typeof value !== 'string') {\n    throw new Error('memory body must be a string.');\n  }\n  if (hasUnsafeControlCharacters(value, true)) {\n    throw new Error('memory body must not contain unsafe control or bidirectional formatting characters.');\n  }\n  const normalized = value.trim();\n  if (normalized.length === 0) {\n    throw new Error('memory body must contain non-whitespace context.');\n  }\n  if (Buffer.byteLength(normalized, 'utf8') > MAX_BODY_BYTES) {\n    throw new Error(`memory body is too large (maximum ${MAX_BODY_BYTES} bytes).`);\n  }\n  return normalized;\n}\n\nfunction normalizeMemory(memory) {\n  if (!memory || typeof memory !== 'object' || Array.isArray(memory)) {\n    throw new Error('memory must be an object.');\n  }\n\n  const targetHarnesses = uniqueStrings(memory.targetHarnesses, {\n    label: 'target harnesses',\n    limit: MAX_TARGETS,\n    validator: value => validateSlug(value, 'target harness'),\n  });\n  if (targetHarnesses.length === 0) {","sourceCodeStart":135,"sourceCodeEnd":171,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/scripts/lib/memory-vault-format.js#L135-L171","documentation":"normalizeBody trims the input and throws if nothing remains — a body consisting solely of whitespace (spaces, tabs, newlines) is rejected. Every memory must carry actual non-whitespace content to be worth storing in the vault.","triggerScenarios":"Calling normalizeMemory with body '', '   ', '\\n\\t', or a string of only whitespace characters; also produced when an upstream strip of control characters left an originally non-empty string blank.","commonSituations":"A generator that created a memory file but never filled the body; a template with an unfilled placeholder that collapsed to whitespace; an aggressive sanitizer removing all content; conditional writes where the body variable was initialized to '' and never set.","solutions":["Ensure the body has real content before calling; guard with if (body.trim()) before saving.","Fix the generator/template so the body placeholder is populated.","Skip creating the memory entirely when there is no content rather than writing an empty stub.","If a sanitization step emptied the body, treat that as an error upstream and do not persist."],"exampleFix":"// before\nsaveMemory({ title: 'notes', body: placeholder /* '' */ })\n// after\nconst body = placeholder.trim();\nif (body) saveMemory({ title: 'notes', body });","handlingStrategy":"validation","validationCode":"const trimmed = typeof body === 'string' ? body.trim() : '';\nif (!trimmed) throw new Error('refusing to save memory with empty body');","typeGuard":"const hasContent = (v) => typeof v === 'string' && v.trim().length > 0;","tryCatchPattern":"try { normalizeMemory(mem); } catch (e) { if (e.message.includes('non-whitespace context')) { console.warn('skipping empty memory', mem.title); return null; } throw e; }","preventionTips":["Guard every save with a body.trim() truthiness check","Never create placeholder/stub memories with unfilled bodies","Fix generators to fail early when a template variable is empty","Treat a whitespace-only sanitize result as an upstream failure"],"tags":["validation","empty","memory-vault"],"backgroundTag":"empty-required-field","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"}