{"record":{"id":"9efc780988d6b9b9","repo":"pbakaus/impeccable","slug":"config-exclude-if-present-must-be-a-string-array-9efc78","errorCode":null,"errorMessage":"config.exclude, if present, must be a string array","messagePattern":"config\\.exclude, if present, must be a string array","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"skill/scripts/live-inject.mjs","lineNumber":459,"sourceCode":"  }\n  return new RegExp('^' + re + '$');\n}\n\n// ---------------------------------------------------------------------------\n// Core operations\n// ---------------------------------------------------------------------------\n\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","sourceCodeStart":441,"sourceCodeEnd":477,"githubUrl":"https://github.com/pbakaus/impeccable/blob/d14711ae3d1a1dd62dee61a358d27f107c51ccd0/skill/scripts/live-inject.mjs#L441-L477","documentation":"Thrown by validateConfig() in live-inject.mjs when a config.json contains an 'exclude' field that is not an Array. validateConfig guards every shape of the Impeccable Live injection config before any file mutation happens, so injection aborts up front rather than writing partial output. The check is Array.isArray(cfg.exclude) — anything else (object, string, number, null) trips it.","triggerScenarios":"validateConfig(cfg) is called with a parsed config.json whose 'exclude' key exists but is not an array — e.g. \"exclude\": \"*.test.js\" (string) or \"exclude\": {\"glob\": \"*.test.js\"} (object) or \"exclude\": null. The undefined case is intentionally allowed (the guard only runs when cfg.exclude !== undefined).","commonSituations":"Author hand-edits config.json and writes exclude as a single glob string instead of a one-element array; a generator/template emits exclude as an object; JSON5/JSON copy-paste from docs that used a shorthand notation. Often appears right after a user first discovers they need to exclude test fixtures from live injection.","solutions":["Set 'exclude' to an array of glob strings, e.g. \"exclude\": [\"**/*.test.js\", \"**/*.spec.js\"].","If you do not need exclusions, delete the 'exclude' key entirely (undefined is valid).","Validate the file with a JSON schema or run the injector with a dry-run/validate mode before applying."],"exampleFix":"// before\n{\n  \"files\": [\"src/**/*.html\"],\n  \"exclude\": \"**/*.test.html\",\n  \"insertAfter\": \"<head>\",\n  \"commentSyntax\": \"html\"\n}\n// after\n{\n  \"files\": [\"src/**/*.html\"],\n  \"exclude\": [\"**/*.test.html\"],\n  \"insertAfter\": \"<head>\",\n  \"commentSyntax\": \"html\"\n}","handlingStrategy":"validation","validationCode":"// Before calling validateConfig / the injector:\nfunction isStringArray(v) {\n  return Array.isArray(v) && v.every((x) => typeof x === 'string' && x.length > 0);\n}\nif (cfg.exclude !== undefined && !isStringArray(cfg.exclude)) {\n  throw new Error('cfg.exclude must be a non-empty-string array');\n}","typeGuard":"function isOptionalStringArray(v): v is string[] {\n  return v === undefined || (Array.isArray(v) && v.every((x) => typeof x === 'string' && x.length > 0));\n}","tryCatchPattern":null,"preventionTips":["Author config.json with a JSON schema that types 'exclude' as string[] and run ajv/validate before invoking the injector.","Build exclude arrays programmatically with .push() of string literals only — never push objects or undefined.","Treat validateConfig failures as cheap: the injector writes nothing on validation failure, so iterate freely."],"tags":["config","validation","live-inject","json"],"backgroundTag":null,"analyzedSha":"d14711ae3d1a1dd62dee61a358d27f107c51ccd0","analyzedAt":"2026-08-13T00:52:25.771Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}