{"record":{"id":"7b782715d73ba754","repo":"pbakaus/impeccable","slug":"config-insertbefore-or-config-insertafter-string","errorCode":null,"errorMessage":"config.insertBefore or config.insertAfter (string) required","messagePattern":"config\\.insertBefore or config\\.insertAfter \\(string\\) required","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"skill/scripts/live-inject.mjs","lineNumber":466,"sourceCode":"\nfunction validateConfig(cfg) {\n  if (!cfg || typeof cfg !== 'object') throw new Error('config.json must be an object');\n  if (!Array.isArray(cfg.files) || cfg.files.length === 0) {\n    throw new Error('config.files (non-empty string array) required');\n  }\n  if (!cfg.files.every((f) => typeof f === 'string' && f.length > 0)) {\n    throw new Error('config.files must contain only non-empty strings');\n  }\n  if (cfg.exclude !== undefined) {\n    if (!Array.isArray(cfg.exclude)) {\n      throw new Error('config.exclude, if present, must be a string array');\n    }\n    if (!cfg.exclude.every((f) => typeof f === 'string' && f.length > 0)) {\n      throw new Error('config.exclude must contain only non-empty strings');\n    }\n  }\n  if (typeof cfg.insertBefore !== 'string' && typeof cfg.insertAfter !== 'string') {\n    throw new Error('config.insertBefore or config.insertAfter (string) required');\n  }\n  if (cfg.commentSyntax !== 'html' && cfg.commentSyntax !== 'jsx') {\n    throw new Error(\"config.commentSyntax must be 'html' or 'jsx'\");\n  }\n  if (cfg.cspChecked !== undefined && typeof cfg.cspChecked !== 'boolean') {\n    throw new Error(\"config.cspChecked, if present, must be a boolean\");\n  }\n}\n\n// ---------------------------------------------------------------------------\n// Auto-execute\n// ---------------------------------------------------------------------------\n\nconst _running = process.argv[1];\nif (_running?.endsWith('live-inject.mjs') || _running?.endsWith('live-inject.mjs/')) {\n  enterLiveRoot();\n  injectCli();\n}","sourceCodeStart":448,"sourceCodeEnd":484,"githubUrl":"https://github.com/pbakaus/impeccable/blob/f88b2837a7d7c3182e46307bbbb091a1ed547571/skill/scripts/live-inject.mjs#L448-L484","documentation":"validateConfig() requires an insertion anchor: cfg.insertBefore or cfg.insertAfter (or both) must be a string. The check throws only when NEITHER is a string — both missing, or both present with non-string values (numbers, null). The anchor tells the injector where the script/comment block goes relative to existing markup.","triggerScenarios":"Config has neither insertBefore nor insertAfter; or insertBefore: 123 / null while insertAfter is also absent or non-string. Providing exactly one string (the normal case) or both as strings passes.","commonSituations":"Trimmed-down configs copied from another project that relied on a default (there is no default anchor); renaming the key (e.g. 'insertBeforeTag') during hand edits; YAML-to-JSON conversions dropping empty values.","solutions":["Add a string anchor, e.g. \"insertAfter\": \"</title>\" or \"insertBefore\": \"</body>\" — the literal markup the injector searches for","Ensure the value is a quoted string, not a number or null","Pick an anchor that actually exists in the target files, otherwise the inject run fails later with a not-found error"],"exampleFix":"// before\n{ \"files\": [\"index.html\"], \"commentSyntax\": \"html\" }\n\n// after\n{ \"files\": [\"index.html\"], \"insertAfter\": \"</title>\", \"commentSyntax\": \"html\" }","handlingStrategy":"validation","validationCode":"const hasAnchor = typeof cfg.insertBefore === 'string' || typeof cfg.insertAfter === 'string';\nif (!hasAnchor) throw new TypeError('config needs insertBefore or insertAfter as a string');\n// Bonus: confirm the anchor actually occurs in a target file before injecting.\nimport fs from 'node:fs';\nconst sample = cfg.files.find((f) => fs.existsSync(f));\nif (sample && !fs.readFileSync(sample, 'utf-8').includes(cfg.insertAfter ?? cfg.insertBefore)) {\n  console.warn('anchor string not found in sample file — inject will fail later');\n}","typeGuard":"const hasInsertAnchor = (cfg) =>\n  typeof cfg?.insertBefore === 'string' || typeof cfg?.insertAfter === 'string';","tryCatchPattern":null,"preventionTips":["There is no default anchor — always author one explicitly per project layout","Choose stable anchors (</title>, </body>) that exist in every matched file","Keep the value a quoted string; numbers/null do not satisfy the check"],"tags":["config","schema","anchor","live-inject"],"backgroundTag":"config-schema-validation","analyzedSha":"f88b2837a7d7c3182e46307bbbb091a1ed547571","analyzedAt":"2026-08-18T04:58:36.608Z","contentChangedAt":"2026-08-18T04:58:36.608Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}