Wrap all JSON.parse calls with try-catch

This commit is contained in:
Misode
2024-10-26 21:49:12 +02:00
parent 6555e80ead
commit 2ff59b8405
19 changed files with 65 additions and 58 deletions

View File

@@ -623,3 +623,11 @@ export function makeDescriptionId(prefix: string, id: Identifier | undefined) {
}
return `${prefix}.${id.namespace}.${id.path.replaceAll('/', '.')}`
}
export function safeJsonParse(text: string): any {
try {
return JSON.parse(text)
} catch (e) {
return undefined
}
}