{"record":{"id":"fa7b4df498e44b8a","repo":"diegosouzapw/OmniRoute","slug":"existing-opencode-config-is-invalid-jsonc-detai","errorCode":null,"errorMessage":"Existing OpenCode config is invalid JSONC (${detail}); refusing to overwrite it.","messagePattern":"Existing OpenCode config is invalid JSONC \\((.+?)\\); refusing to overwrite it\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/shared/services/opencodeConfig.ts","lineNumber":167,"sourceCode":"  input: OpenCodeConfigInput\n) => {\n  const providerConfig = buildOpenCodeProviderConfig(input);\n  const v2ProviderConfig = buildOpenCodeV2ProviderConfig(input);\n  const content = typeof existingText === \"string\" ? existingText : \"\";\n  const trimmedContent = content.trim();\n\n  if (!trimmedContent) {\n    return JSON.stringify(buildOpenCodeConfigDocument(input), null, 2);\n  }\n\n  const errors: ParseError[] = [];\n  const parsed = parse(content, errors, { allowTrailingComma: true, disallowComments: false });\n\n  if (errors.length > 0 || !parsed || typeof parsed !== \"object\" || Array.isArray(parsed)) {\n    const detail = errors[0]\n      ? `${printParseErrorCode(errors[0].error)} at offset ${errors[0].offset}`\n      : \"root must be an object\";\n    throw new Error(\n      `Existing OpenCode config is invalid JSONC (${detail}); refusing to overwrite it.`\n    );\n  }\n\n  let nextText = content;\n\n  const schemaEdits = modify(\n    nextText,\n    [\"$schema\"],\n    parsed.$schema || \"https://opencode.ai/config.json\",\n    {\n      formattingOptions: { insertSpaces: true, tabSize: 2 },\n    }\n  );\n  nextText = applyEdits(nextText, schemaEdits);\n\n  const providerEdits = modify(nextText, [\"provider\", \"omniroute\"], providerConfig, {\n    formattingOptions: { insertSpaces: true, tabSize: 2 },","sourceCodeStart":149,"sourceCodeEnd":185,"githubUrl":"https://github.com/diegosouzapw/OmniRoute/blob/a179ffed5bb2e0b883b9ae7214ce8717b2a94c4d/src/shared/services/opencodeConfig.ts#L149-L185","documentation":"Safety error in the OpenCode config writer: the existing config file on disk is not valid JSONC (parse errors, or parsed to a non-object/array), so the merge-and-write path refuses to overwrite it. This protects user edits and unknown content from being destroyed by regeneration.","triggerScenarios":"Thrown at src/shared/services/opencodeConfig.ts:167 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Fix or remove the JSONC syntax error reported in `detail` (trailing commas are allowed; comments are OK)","Back up the broken config, then delete or rename it so a fresh one can be generated","Re-run the config apply after the file parses cleanly","Do not write raw JSON5/JS object literals into opencode.json — keep it JSONC"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"a179ffed5bb2e0b883b9ae7214ce8717b2a94c4d","analyzedAt":"2026-08-25T18:35:09.898Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}