{"record":{"id":"d91cb2865e8248f2","repo":"coder/code-server","slug":"invalid-json-in-custom-strings-file-filepath-n","errorCode":null,"errorMessage":"Invalid JSON in custom strings file: ${filePath}\\n${error.message}","messagePattern":"Invalid JSON in custom strings file: (.+?)\\\\n(.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/node/i18n/index.ts","lineNumber":41,"sourceCode":"    translation: ur,\n  },\n}\n\nexport async function loadCustomStrings(filePath: string): Promise<void> {\n  try {\n    // Read custom strings from file path only\n    const fileContent = await fs.readFile(filePath, \"utf8\")\n    const customStringsData = JSON.parse(fileContent)\n\n    // User-provided strings override all languages.\n    Object.keys(defaultResources).forEach((locale) => {\n      i18next.addResourceBundle(locale, \"translation\", customStringsData)\n    })\n  } catch (error) {\n    if (error && typeof error === \"object\" && \"code\" in error && error.code === \"ENOENT\") {\n      throw new Error(`Custom strings file not found: ${filePath}\\nPlease ensure the file exists and is readable.`)\n    } else if (error instanceof SyntaxError) {\n      throw new Error(`Invalid JSON in custom strings file: ${filePath}\\n${error.message}`)\n    } else {\n      throw new Error(\n        `Failed to load custom strings from ${filePath}: ${error instanceof Error ? error.message : String(error)}`,\n      )\n    }\n  }\n}\n\ninit({\n  lng: \"en\",\n  fallbackLng: \"en\", // language to use if translations in user language are not available.\n  returnNull: false,\n  lowerCaseLng: true,\n  debug: process.env.NODE_ENV === \"development\",\n  resources: defaultResources,\n})\n\nexport default i18next","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/coder/code-server/blob/51f90a376b42e217b38937410fe2855e0c1db87e/src/node/i18n/index.ts#L23-L59","documentation":"In the same loadCustomStrings try/catch, if fs.readFile succeeds but JSON.parse throws a SyntaxError, code-server rethrows `Invalid JSON in custom strings file: <path>` with the parser's message. The custom strings feature requires a strict JSON document.","triggerScenarios":"Passing a file to --i18n that is valid text but not valid JSON: trailing commas, single quotes, unquoted keys, comments, or a YAML file mislabeled .json.","commonSituations":"Authoring overrides in YAML/JSON5 by mistake; a concatenation script that joined multiple JSON objects without wrapping them in an array; BOM or smart-quotes pasted from a word processor.","solutions":["Validate with a JSON linter: `npx jsonlint-cli strings.json` or `python -m json.tool strings.json`","Ensure the top-level structure is a JSON object whose keys are translation strings","Re-save the file as UTF-8 without BOM and replace smart quotes with straight quotes"],"exampleFix":"// before (strings.json — invalid: trailing comma)\n{\n  \"key\": \"value\",\n}\n\n// after\n{\n  \"key\": \"value\"\n}","handlingStrategy":"try-catch","validationCode":"function validateCustomStringsJson(path: string): void {\n  JSON.parse(fs.readFileSync(path, \"utf8\")) // throws SyntaxError if invalid\n}","typeGuard":"function isJsonSyntaxError(e: unknown): boolean {\n  return e instanceof SyntaxError\n}","tryCatchPattern":"try {\n  validateCustomStringsJson(args.i18n)\n} catch (e) {\n  if (e instanceof SyntaxError) {\n    throw new Error(`--i18n file is not valid JSON: ${e.message}`)\n  }\n  throw e\n}","preventionTips":["Run `python -m json.tool` or `npx jsonlint` on the file before deploy","Save overrides as plain JSON (no comments, no trailing commas)","Use a schema for translation overrides to catch structural errors"],"tags":["i18n","json","parsing","configuration","startup"],"backgroundTag":null,"analyzedSha":"51f90a376b42e217b38937410fe2855e0c1db87e","analyzedAt":"2026-08-12T11:27:34.273Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}