{"record":{"id":"df768154ab7215d2","repo":"JuliusBrussee/caveman","slug":"name-contains-an-invalid-path-character","errorCode":null,"errorMessage":"${name} contains an invalid path character","messagePattern":"(.+?) contains an invalid path character","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/cli/src/index.ts","lineNumber":11128,"sourceCode":"  if (!(keyPath[keyPath.length - 1]! in cur)) return true;\n  delete cur[keyPath[keyPath.length - 1]!];\n  try {\n    writeFileSync(path, JSON.stringify(root, null, 2) + \"\\n\");\n    return true;\n  } catch (e) {\n    console.error(`${mark(\"warn\")} cannot write ${path}: ${(e as Error).message}`);\n    return false;\n  }\n}\n\ntype KiloConfigLocation = {\n  path: string;\n  jsonc: boolean;\n  source: \"KILO_CONFIG_DIR\" | \"KILO_CONFIG\" | \"XDG_CONFIG_HOME\";\n};\n\nfunction kiloPathFromEnv(value: string, name: string): string {\n  if (/[\\0\\r\\n]/.test(value)) throw new Error(`${name} contains an invalid path character`);\n  // Kilo passes env paths directly to its loader. Shell-style \"~/\" expansion\n  // does not occur inside an environment value; relative paths resolve from cwd.\n  return normalize(isAbsolute(value) ? value : resolve(value));\n}\n\nfunction kiloConfigInDirectory(directory: string, source: KiloConfigLocation[\"source\"]): KiloConfigLocation {\n  // Mirror pinned Kilo's native global writer: prefer an existing canonical\n  // config in this order, otherwise create kilo.json. JSONC stays read-only here\n  // because a JSON stringify would destroy comments.\n  const candidates = [\"kilo.jsonc\", \"kilo.json\", \"opencode.jsonc\", \"opencode.json\"];\n  const selected = candidates.map((name) => join(directory, name)).find((path) => existsSync(path))\n    ?? join(directory, \"kilo.json\");\n  return { path: selected, jsonc: extname(selected).toLowerCase() === \".jsonc\", source };\n}\n\n// Kilo 7.5.6's native config writer targets KILO_CONFIG_DIR when present. That\n// directory is also loaded after KILO_CONFIG, so it must win for effective MCP\n// ownership. Explicit KILO_CONFIG wins only without a custom config directory;","sourceCodeStart":11110,"sourceCodeEnd":11146,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/cli/src/index.ts#L11110-L11146","documentation":"Kilo receives config paths from environment variables and passes them directly to its loader, so the CLI pre-validates them. This error is thrown when KILO_CONFIG_DIR or KILO_CONFIG contains NUL, carriage return, or newline characters, which are invalid in filesystem paths and can silently truncate or corrupt downstream path handling.","triggerScenarios":"Exporting KILO_CONFIG or KILO_CONFIG_DIR with an embedded newline (common when paths are produced by command substitution or copied from terminal output containing line breaks), or a NUL byte from binary-corrupted env sources.","commonSituations":"`export KILO_CONFIG=$(some_command)` where the command outputs a trailing newline captured into the value; YAML/JSON-generated env files with wrapped lines; Windows-to-Unix path migrations leaving stray CR characters.","solutions":["Inspect the variable: `printf '%s' \"$KILO_CONFIG\" | od -c` to find stray \\n or \\r, then re-export a clean value","Use quotes and strip newlines: `export KILO_CONFIG=\"$(command | tr -d '\\r\\n')\"`","Fix the generator (script, env file, direnv config) so it emits a single-line absolute path"],"exampleFix":"// before\nexport KILO_CONFIG=$(op path)\n// after\nexport KILO_CONFIG=\"$(op path | tr -d '\\r\\n')\"","handlingStrategy":"validation","validationCode":"function assertCleanPath(name: string, value?: string) {\n  if (value === undefined) return;\n  if (/[\\0\\r\\n]/.test(value)) throw new Error(`${name} has newline/NUL; re-export a clean single-line path`);\n}\nassertCleanPath(\"KILO_CONFIG\", process.env.KILO_CONFIG);\nassertCleanPath(\"KILO_CONFIG_DIR\", process.env.KILO_CONFIG_DIR);","typeGuard":"function isCleanPathValue(v: unknown): v is string {\n  return typeof v === \"string\" && v.length > 0 && !/[\\0\\r\\n]/.test(v);\n}","tryCatchPattern":"try {\n  await kiloCommand();\n} catch (e) {\n  if ((e as Error).message.includes(\"invalid path character\")) {\n    console.error(\"Fix the env var: export KILO_CONFIG=\\\"$(printf %s $KILO_CONFIG)\\\"\");\n  } else throw e;\n}","preventionTips":["Always quote command substitution: VAR=\"$(cmd)\" and strip newlines with tr -d '\\r\\n'","Inspect env values with `printf %s \"$VAR\" | od -c` when in doubt","Keep env-file generators single-line per variable","Avoid copying paths from terminal output that wraps lines"],"tags":["env-var","path","validation"],"backgroundTag":"invalid-env-var-value","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}