mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
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:
parent
48c27872af
commit
6edce00b1a
@ -211,5 +211,18 @@ export class InspectJSONTab extends PureComponent<Props, State> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getPrettyJSON(obj: any): string {
|
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;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user