{"record":{"id":"64387127f50384a4","repo":"twentyhq/twenty","slug":"jsonc-parse-errors-n-errormessages-join-n","errorCode":null,"errorMessage":"JSONC parse errors:\\n${errorMessages.join('\\n')}","messagePattern":"JSONC parse errors:\\\\n(.+?)","errorType":"exception","errorClass":"JsoncParseError","httpStatus":null,"severity":"error","filePath":"packages/twenty-sdk/src/cli/utilities/file/file-jsonc.ts","lineNumber":37,"sourceCode":"}\n\nexport const parseJsoncString = (\n  content: string,\n  options: JsoncParseOptions = {},\n): any => {\n  const parseErrors: ParseError[] = [];\n\n  const result = parseJsonc(content, parseErrors, {\n    allowTrailingComma: options.allowTrailingComma ?? true,\n    disallowComments: options.disallowComments ?? false,\n    allowEmptyContent: options.allowEmptyContent ?? false,\n  });\n\n  if (parseErrors.length > 0) {\n    const errorMessages = parseErrors.map(\n      (error) => `Line ${error.offset}: ${error.error}`,\n    );\n    throw new JsoncParseError(\n      `JSONC parse errors:\\n${errorMessages.join('\\n')}`,\n      parseErrors,\n    );\n  }\n\n  return result;\n};\n\nexport const parseJsoncFile = async <T = object>(\n  filePath: string,\n  options: JsoncParseOptions = {},\n): Promise<T> => {\n  try {\n    const content = await readFile(filePath, 'utf8');\n    return parseJsoncString(content, options);\n  } catch (error) {\n    if (error instanceof JsoncParseError) {\n      throw new JsoncParseError(error.message, error.parseErrors, filePath);","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/twentyhq/twenty/blob/1f5dd2bbd2a8da3419c8cfd52dd545c0024df1a6/packages/twenty-sdk/src/cli/utilities/file/file-jsonc.ts#L19-L55","documentation":"Thrown by parseJsoncString when the jsonc-parser library reports one or more ParseError entries during parsing of a JSONC (JSON with Comments) string. Each error is formatted as 'Line {offset}: {error}' and all errors are joined with newlines. This wraps structured parse errors into a JsoncParseError exception with the underlying ParseError array attached.","triggerScenarios":"Calling parseJsoncString(content) where content has syntax errors: unclosed braces/brackets, invalid JSON tokens, trailing commas (if allowTrailingComma is false), or disallowed comments (if disallowComments is true). Empty content when allowEmptyContent is false.","commonSituations":"A tsconfig.json or other JSONC config file has a typo (missing comma, unclosed bracket). A trailing comma was left in strict mode. A comment was used in a context where comments are disallowed. The file was partially written (interrupted save) leaving truncated JSON.","solutions":["Read the error message — it lists each parse error with its offset and description.","Open the file in a JSONC-aware editor (VS Code) which will highlight syntax errors visually.","Validate the file with an online JSONC validator or jsonc-parser directly.","If the error is about trailing commas, pass { allowTrailingComma: true } to parseJsoncString.","If the error is about comments, pass { disallowComments: false } (the default) or remove the comments."],"exampleFix":"// before — file has a trailing comma\n{ \"name\": \"app\", \"version\": \"1.0\", }\n\n// after\n{ \"name\": \"app\", \"version\": \"1.0\" }","handlingStrategy":"validation","validationCode":"import { parse as parseJsonc, type ParseError } from 'jsonc-parser';\n\nconst validateJsonc = (content: string): ParseError[] => {\n  const errors: ParseError[] = [];\n  parseJsonc(content, errors, { allowTrailingComma: true });\n  return errors;\n};\n\nconst errors = validateJsonc(fileContent);\nif (errors.length > 0) {\n  console.error('JSONC errors:', errors.map((e) => `offset ${e.offset}: ${e.error}`));\n}","typeGuard":"import { JsoncParseError } from '@/cli/utilities/file/file-jsonc';\n\nconst isJsoncParseError = (error: unknown): error is JsoncParseError => {\n  return error instanceof JsoncParseError;\n};","tryCatchPattern":"import { JsoncParseError, parseJsoncString } from '@/cli/utilities/file/file-jsonc';\n\ntry {\n  const result = parseJsoncString(content);\n} catch (error) {\n  if (error instanceof JsoncParseError) {\n    error.parseErrors.forEach((pe) => {\n      console.error(`Offset ${pe.offset}: ${pe.error}`);\n    });\n    return;\n  }\n  throw error;\n}","preventionTips":["Use a JSONC-aware editor (VS Code) to catch syntax errors before runtime.","Validate JSONC files after manual edits with a parser check.","Pass the appropriate options (allowTrailingComma, disallowComments) matching your file's conventions."],"tags":["sdk-cli","jsonc","parsing","validation"],"backgroundTag":null,"analyzedSha":"1f5dd2bbd2a8da3419c8cfd52dd545c0024df1a6","analyzedAt":"2026-08-12T15:37:27.593Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}