Skip to content

Commit ec69ea2

Browse files
committed
Improves JSON syntax error handling in import flow
Provides more informative error messages for JSON syntax errors by extracting the error position and formatting it for clarity during import. Enhances user feedback when invalid JSON is encountered.
1 parent 56f042b commit ec69ea2

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/core/config/importExport.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,15 @@ export const importSettings = async ({ providerSettingsManager, contextProxy, cu
8484
if (e instanceof ZodError) {
8585
error = e.issues.map((issue) => `[${issue.path.join(".")}]: ${issue.message}`).join("\n")
8686
telemetryService.captureSchemaValidationError({ schemaName: "ImportExport", error: e })
87+
} else if (e instanceof SyntaxError) {
88+
// Extract position info from the error message
89+
const match = e.message.match(/at position (\d+)/)
90+
if (match) {
91+
const position = parseInt(match[1], 10)
92+
error = `Expected property name or '}' in JSON at position ${position}`
93+
} else {
94+
error = e.message
95+
}
8796
} else if (e instanceof Error) {
8897
error = e.message
8998
}

0 commit comments

Comments
 (0)