summaryrefslogtreecommitdiffhomepage
path: root/packages
diff options
context:
space:
mode:
authorAiden Cline <[email protected]>2025-08-01 18:10:32 -0500
committerGitHub <[email protected]>2025-08-01 19:10:32 -0400
commit80d68d01f4330a8a80c9ace32dffae7c1cc6d81d (patch)
tree325fa09dbbb717b1f7f559212abda61b9bab27ba /packages
parentfa9db3c16799a003b58f503f776c4b7339036499 (diff)
downloadopencode-80d68d01f4330a8a80c9ace32dffae7c1cc6d81d.tar.gz
opencode-80d68d01f4330a8a80c9ace32dffae7c1cc6d81d.zip
better configuration error messages (#1517)
Diffstat (limited to 'packages')
-rw-r--r--packages/opencode/src/config/config.ts24
1 files changed, 16 insertions, 8 deletions
diff --git a/packages/opencode/src/config/config.ts b/packages/opencode/src/config/config.ts
index b0ba6fa47..d00e5f1f9 100644
--- a/packages/opencode/src/config/config.ts
+++ b/packages/opencode/src/config/config.ts
@@ -412,16 +412,24 @@ export namespace Config {
const errors: JsoncParseError[] = []
const data = parseJsonc(text, errors, { allowTrailingComma: true })
if (errors.length) {
+ const lines = text.split("\n")
+ const errorDetails = errors
+ .map((e) => {
+ const beforeOffset = text.substring(0, e.offset).split("\n")
+ const line = beforeOffset.length
+ const column = beforeOffset[beforeOffset.length - 1].length + 1
+ const problemLine = lines[line - 1]
+
+ const error = `${printParseErrorCode(e.error)} at line ${line}, column ${column}`
+ if (!problemLine) return error
+
+ return `${error}\n Line ${line}: ${problemLine}\n${"".padStart(column + 9)}^`
+ })
+ .join("\n")
+
throw new JsonError({
path: configPath,
- message: errors
- .map((e) => {
- const lines = text.substring(0, e.offset).split("\n")
- const line = lines.length
- const column = lines[lines.length - 1].length + 1
- return `${printParseErrorCode(e.error)} at line ${line}, column ${column}`
- })
- .join("; "),
+ message: `\n--- JSONC Input ---\n${text}\n--- Errors ---\n${errorDetails}\n--- End ---`,
})
}