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

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

* message update when JSON stringify fails due to obj size

(cherry picked from commit 6edce00b1a)

Co-authored-by: Alex <TsotosA@users.noreply.github.com>
This commit is contained in:
Grot (@grafanabot)
2022-10-17 06:10:54 -07:00
committed by GitHub
co-authored by Alex
parent a3f69498f6
commit c2ce0e82ff
@@ -196,5 +196,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;
}