{"record":{"id":"d5c8d532f02f3428","repo":"affaan-m/ECC","slug":"duplicate-memory-frontmatter-field-in-sourcepath","errorCode":null,"errorMessage":"Duplicate memory frontmatter field in ${sourcePath}.","messagePattern":"Duplicate memory frontmatter field in (.+?)\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/lib/memory-vault-format.js","lineNumber":233,"sourceCode":"  try {\n    return FATAL_UTF8_DECODER.decode(buffer);\n  } catch {\n    throw new Error(`${label} must contain valid UTF-8 text.`);\n  }\n}\n\nfunction parseFrontmatterLine(line, sourcePath, seen) {\n  const separator = line.indexOf(':');\n  if (separator <= 0) {\n    throw new Error(`Invalid memory frontmatter line in ${sourcePath}.`);\n  }\n  const serializedKey = line.slice(0, separator).trim();\n  const objectKey = FRONTMATTER_KEYS.get(serializedKey);\n  if (!objectKey) {\n    throw new Error(`Unknown memory frontmatter field in ${sourcePath}.`);\n  }\n  if (seen.has(objectKey)) {\n    throw new Error(`Duplicate memory frontmatter field in ${sourcePath}.`);\n  }\n  const rawValue = line.slice(separator + 1).trim();\n  try {\n    return { objectKey, value: JSON.parse(rawValue) };\n  } catch {\n    throw new Error(`Memory frontmatter field in ${sourcePath} must use a JSON value.`);\n  }\n}\n\nfunction parseMemoryDocument(source, sourcePath = '<memory>') {\n  const openingMarker = typeof source === 'string'\n    ? /^---\\r?\\n/.exec(source)\n    : null;\n  if (!openingMarker) {\n    throw new Error(`Memory document ${sourcePath} must start with --- frontmatter.`);\n  }\n  if (Buffer.byteLength(source, 'utf8') > MAX_DOCUMENT_BYTES) {\n    throw new Error(`Memory document ${sourcePath} is too large.`);","sourceCodeStart":215,"sourceCodeEnd":251,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/scripts/lib/memory-vault-format.js#L215-L251","documentation":"parseFrontmatterLine() tracks which object keys have already been seen (via the `seen` set) across the frontmatter block. Because each frontmatter field maps to exactly one memory property, a second occurrence of the same key is ambiguous and is rejected instead of last-value-wins.","triggerScenarios":"A memory document whose frontmatter block contains the same field twice, e.g. two `title:` lines or two `id:` lines (possibly with different serialized spellings mapping to the same object key); concatenating two documents' frontmatter.","commonSituations":"Merge-conflict resolution in git that duplicated a line; appending an updated field instead of editing the existing one; copy-paste of a field while hand-editing the markdown vault.","solutions":["Delete the duplicate line, keeping the one with the correct value.","Search the frontmatter block for the field name and keep a single occurrence.","Resolve any git conflict markers and ensure the merged document has each field exactly once.","Regenerate the document via the library's save path to guarantee canonical single-occurrence frontmatter."],"exampleFix":"// before\n---\nid: \"notes\"\nid: \"notes-v2\"\ntitle: \"Deploy notes\"\n---\n\n// after\n---\nid: \"notes-v2\"\ntitle: \"Deploy notes\"\n---","handlingStrategy":"validation","validationCode":"const keys = frontmatterLines.map(l => l.slice(0, l.indexOf(':')).trim());\nconst dupes = keys.filter((k, i) => keys.indexOf(k) !== i);\nif (dupes.length) throw new Error(`Duplicate frontmatter keys: ${dupes.join(', ')}`);","typeGuard":"const hasNoDuplicateKeys = (lines) => new Set(lines.map(l => l.split(':')[0].trim())).size === lines.length;","tryCatchPattern":"try {\n  parseMemoryDocument(source, path);\n} catch (err) {\n  if (err.message.includes('Duplicate memory frontmatter field')) {\n    console.error('A field appears twice in %s frontmatter; keep exactly one occurrence.', path);\n  } else throw err;\n}","preventionTips":["After git merges, grep the frontmatter block for repeated keys.","Edit field values in place rather than appending a second line.","Regenerate documents with the library writer to guarantee uniqueness."],"tags":["parsing","frontmatter","duplicate"],"backgroundTag":"duplicate-config-key","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"}