MISC: Add error cause to exceptionAlert and Recovery mode (#1772)

This commit is contained in:
catloversg
2024-11-13 10:27:18 +07:00
committed by GitHub
parent 246d668951
commit 4f84a894eb
3 changed files with 83 additions and 15 deletions
+16 -1
View File
@@ -50,7 +50,22 @@ export function AlertManager({ hidden }: { hidden: boolean }): React.ReactElemen
if (typeof text === "string") {
return cyrb53(text);
}
return cyrb53(JSON.stringify(text.props));
/**
* JSON.stringify may throw an error in edge cases. One possible error is "TypeError: Converting circular structure
* to JSON". It may happen in very special cases. This is the flow of one of them:
* - An error occurred in GameRoot.tsx and we show a warning popup by calling "exceptionAlert" without delaying.
* - "exceptionAlert" constructs a React element and passes it via "dialogBoxCreate" -> "AlertEvents.emit".
* - When we receive the final React element here, the element's "props" property may contain a circular structure.
*/
let textPropsAsString;
try {
textPropsAsString = JSON.stringify(text.props);
} catch (e) {
console.error(e);
// Use the current timestamp as the fallback value.
textPropsAsString = Date.now().toString();
}
return cyrb53(textPropsAsString);
}
function close(): void {