affaan-m/ECC · error · Error

Memory document ${sourcePath} has no closing frontmatter mar

Error message

Memory document ${sourcePath} has no closing frontmatter marker.

What it means

Thrown by parseMemoryDocument() when the regex /\r?\n---(?=\r?\n|$)/ finds no match in the remainder after the opening marker. The closing frontmatter marker must be a line containing exactly '---' preceded by a newline and followed by a newline or end-of-string. Without it, the parser cannot tell where metadata ends and body begins.

Source

Thrown at scripts/lib/memory-vault-format.js:258

  }
}

function parseMemoryDocument(source, sourcePath = '<memory>') {
  const openingMarker = typeof source === 'string'
    ? /^---\r?\n/.exec(source)
    : null;
  if (!openingMarker) {
    throw new Error(`Memory document ${sourcePath} must start with --- frontmatter.`);
  }
  if (Buffer.byteLength(source, 'utf8') > MAX_DOCUMENT_BYTES) {
    throw new Error(`Memory document ${sourcePath} is too large.`);
  }

  const frontmatterStart = openingMarker[0].length;
  const remainder = source.slice(frontmatterStart);
  const closingMarker = /\r?\n---(?=\r?\n|$)/.exec(remainder);
  if (!closingMarker) {
    throw new Error(`Memory document ${sourcePath} has no closing frontmatter marker.`);
  }

  const frontmatterSource = remainder.slice(0, closingMarker.index);
  const parsed = frontmatterSource.split(/\r?\n/).reduce((state, line) => {
    const next = parseFrontmatterLine(line, sourcePath, state.seen);
    return {
      values: { ...state.values, [next.objectKey]: next.value },
      seen: new Set([...state.seen, next.objectKey]),
    };
  }, { values: {}, seen: new Set() });

  const missing = FRONTMATTER_FIELDS
    .map(([, objectKey]) => objectKey)
    .filter(objectKey => !parsed.seen.has(objectKey));
  if (missing.length > 0) {
    throw new Error(`Memory document ${sourcePath} is missing fields: ${missing.join(', ')}.`);
  }

View on GitHub (pinned to 01e15490f0)

Solutions

  1. Inspect the file and add a '\n---\n' line after the last frontmatter field.
  2. Ensure the closing marker is exactly three dashes on its own line with no trailing spaces.
  3. If using a text editor, turn off 'trim trailing whitespace' or 'ensure newline at EOF' for vault files, or always regenerate via serializeMemoryDocument().
  4. Restore from version control if a partial write is suspected.

Example fix

// before
---
title: "x"
kind: "note"
body text starts here without a closing marker

// after
---
title: "x"
kind: "note"
---

body text starts here
Defensive patterns

Strategy: validation

Validate before calling

const opening = /^---\r?\n/.exec(source);
if (opening && !/\r?\n---(?=\r?\n|$)/.test(source.slice(opening[0].length))) {
  throw new Error('memory document is missing the closing --- frontmatter marker');
}

Prevention

When it happens

Trigger: A file with an opening '---\n' but no closing marker. A closing marker '--- ' with trailing spaces. A closing marker on the same line as content. A file truncated mid-frontmatter by a crashed write. A document with four dashes '----' instead of three.

Common situations: Editor that strips trailing newlines, leaving '---' at EOF without a following newline. Hand-edit that deleted the closing marker. Partial write from a process killed mid-save. AI agent that emitted only an opening marker.

Related errors


AI-assisted analysis of affaan-m/ECC@01e15490f0 (2026-08-13). Data as JSON: /api/errors/d50aa5cf088b5ca4. Report an issue: GitHub.