Skip to content

Commit

Permalink
Fix issue when stringify function would throw an error when stringify…
Browse files Browse the repository at this point in the history
…ing unloaded entity
  • Loading branch information
stirante committed Mar 27, 2024
1 parent 6cc01a5 commit 03e8d02
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 3 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
"minecraft-linting/avoid-unnecessary-command": "error",
"prefer-const": "warn",
"@typescript-eslint/no-explicit-any": "off",
"eslint-disable no-unused-labels": "off"
"eslint-disable no-unused-labels": "off",
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": "warn"
}
}
9 changes: 8 additions & 1 deletion src/ColorJSON.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export default class ColorJSON {
* Transforms a function into a JSON representation.
* @param value - The function to transform.
*/
// eslint-disable-next-line @typescript-eslint/ban-types
protected stringifyFunction(value: Function): string {
// Functions are transformed to predefined function token
return this.FunctionColor + this.FunctionValue + ChatColor.RESET;
Expand Down Expand Up @@ -244,7 +245,13 @@ export default class ColorJSON {
// Sort the keys
const allKeys = [...keySet].sort();
// Get all entries
const entries = allKeys.map((key: string) => [key, (value as any)[key] ?? undefined]).filter(([key, val]) => typeof val !== 'function' && val !== void 0);
const entries = allKeys.map((key: string) => {
try {
return [key, (value as any)[key] ?? void 0];
} catch(e) {
return [key, void 0];
}
}).filter(([, val]) => typeof val !== 'function' && val !== void 0);
const result = this.stringifyObject(value, name, entries, indentLevel);
this.clearCycle(value);
return result;
Expand Down

0 comments on commit 03e8d02

Please sign in to comment.