coder/code-server · error · Error

Invalid JSON in custom strings file: ${filePath}\n${error.me

Error message

Invalid JSON in custom strings file: ${filePath}\n${error.message}

What it means

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.

Source

Thrown at src/node/i18n/index.ts:41

    translation: ur,
  },
}

export async function loadCustomStrings(filePath: string): Promise<void> {
  try {
    // Read custom strings from file path only
    const fileContent = await fs.readFile(filePath, "utf8")
    const customStringsData = JSON.parse(fileContent)

    // User-provided strings override all languages.
    Object.keys(defaultResources).forEach((locale) => {
      i18next.addResourceBundle(locale, "translation", customStringsData)
    })
  } catch (error) {
    if (error && typeof error === "object" && "code" in error && error.code === "ENOENT") {
      throw new Error(`Custom strings file not found: ${filePath}\nPlease ensure the file exists and is readable.`)
    } else if (error instanceof SyntaxError) {
      throw new Error(`Invalid JSON in custom strings file: ${filePath}\n${error.message}`)
    } else {
      throw new Error(
        `Failed to load custom strings from ${filePath}: ${error instanceof Error ? error.message : String(error)}`,
      )
    }
  }
}

init({
  lng: "en",
  fallbackLng: "en", // language to use if translations in user language are not available.
  returnNull: false,
  lowerCaseLng: true,
  debug: process.env.NODE_ENV === "development",
  resources: defaultResources,
})

export default i18next

View on GitHub (pinned to 51f90a376b)

Solutions

  1. Validate with a JSON linter: `npx jsonlint-cli strings.json` or `python -m json.tool strings.json`
  2. Ensure the top-level structure is a JSON object whose keys are translation strings
  3. Re-save the file as UTF-8 without BOM and replace smart quotes with straight quotes

Example fix

// before (strings.json — invalid: trailing comma)
{
  "key": "value",
}

// after
{
  "key": "value"
}
Defensive patterns

Strategy: try-catch

Validate before calling

function validateCustomStringsJson(path: string): void {
  JSON.parse(fs.readFileSync(path, "utf8")) // throws SyntaxError if invalid
}

Type guard

function isJsonSyntaxError(e: unknown): boolean {
  return e instanceof SyntaxError
}

Try / catch

try {
  validateCustomStringsJson(args.i18n)
} catch (e) {
  if (e instanceof SyntaxError) {
    throw new Error(`--i18n file is not valid JSON: ${e.message}`)
  }
  throw e
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Related errors


AI-assisted analysis of coder/code-server@51f90a376b (2026-08-12). Data as JSON: /api/errors/d91cb2865e8248f2. Report an issue: GitHub.