mirror of
https://github.com/aljazceru/opencode.git
synced 2025-12-22 10:14:22 +01:00
better configuration error messages (#1517)
This commit is contained in:
@@ -412,16 +412,24 @@ export namespace Config {
|
|||||||
const errors: JsoncParseError[] = []
|
const errors: JsoncParseError[] = []
|
||||||
const data = parseJsonc(text, errors, { allowTrailingComma: true })
|
const data = parseJsonc(text, errors, { allowTrailingComma: true })
|
||||||
if (errors.length) {
|
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({
|
throw new JsonError({
|
||||||
path: configPath,
|
path: configPath,
|
||||||
message: errors
|
message: `\n--- JSONC Input ---\n${text}\n--- Errors ---\n${errorDetails}\n--- End ---`,
|
||||||
.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("; "),
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user