Inspect: Handle JSON tab crash when the provided object is too big to stringify. (#55939)

* fix(inspector): handle json tab crash when too much data

* message update when JSON stringify fails due to obj size
This commit is contained in:
Alex 2022-10-12 10:52:23 +03:00 committed by GitHub
parent 48c27872af
commit 6edce00b1a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -211,5 +211,18 @@ export class InspectJSONTab extends PureComponent<Props, State> {
}
function getPrettyJSON(obj: any): string {
return JSON.stringify(obj, null, 2);
let r = '';
try {
r = JSON.stringify(obj, null, 2);
} catch (e) {
if (
e instanceof Error &&
(e.toString().includes('RangeError') || e.toString().includes('allocation size overflow'))
) {
appEvents.emit(AppEvents.alertError, [e.toString(), 'Cannot display JSON, the object is too big.']);
} else {
appEvents.emit(AppEvents.alertError, [e instanceof Error ? e.toString() : e]);
}
}
return r;
}