Skip to content

Commit 447d7b0

Browse files
committed
🛠️ Fix: Export crashes when reading invalid JSON in function tags.
1 parent 8070253 commit 447d7b0

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/systems/datapackCompiler/index.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -996,9 +996,18 @@ export default async function compileDataPack(options: {
996996
}
997997
}
998998
// Remove mentions of the export namespace from the file
999-
const content: IFunctionTag = JSON.parse(
1000-
(await fs.promises.readFile(file)).toString()
1001-
)
999+
let content: IFunctionTag
1000+
// Remove mentions of the export namespace from the file
1001+
try {
1002+
content = JSON.parse((await fs.promises.readFile(file)).toString())
1003+
} catch (e) {
1004+
if (e instanceof SyntaxError) {
1005+
throw new IntentionalExportError(
1006+
`Failed to parse function tag file: '${file}'. Please ensure that the file is valid JSON.`
1007+
)
1008+
}
1009+
continue
1010+
}
10021011
content.values = content.values.filter(
10031012
v =>
10041013
typeof v === 'string' &&

0 commit comments

Comments
 (0)