12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- import {defined} from 'sentry/utils';
- import type {BreadcrumbFrame, ConsoleFrame} from 'sentry/utils/replays/types';
- import {isConsoleFrame} from 'sentry/utils/replays/types';
- import Format from 'sentry/views/replays/detail/console/format';
- import type {OnExpandCallback} from 'sentry/views/replays/detail/useVirtualizedInspector';
- interface Props {
- frame: BreadcrumbFrame;
- onExpand: OnExpandCallback;
- expandPaths?: string[];
- }
- function isSerializedError(frame: ConsoleFrame) {
- const args = frame.data.arguments;
- return (
- frame.message &&
- typeof frame.message === 'string' &&
- Array.isArray(args) &&
- args.length <= 2 &&
- args[0] &&
- typeof args[0] === 'object' &&
- Object.keys(args[0]).length === 0
- );
- }
- export default function MessageFormatter({frame, expandPaths, onExpand}: Props) {
- if (!isConsoleFrame(frame)) {
- return (
- <Format
- expandPaths={expandPaths}
- onExpand={onExpand}
- args={[frame.category, frame.message, frame.data].filter(defined)}
- />
- );
- }
- const args = frame.data.arguments;
-
- if (args && isSerializedError(frame)) {
-
- const splitMessage = frame.message.split('\n');
- const errorMessagePiece = splitMessage[0]!.trim();
-
-
-
- const errorMessageSplit = errorMessagePiece.split('Error: ');
-
- const errorMessage = errorMessageSplit
- .splice(errorMessageSplit.length - 1)
- .join('Error: ');
- const fakeError = new Error(errorMessage);
- try {
-
- fakeError.stack = args.length === 2 ? (args[1] as string) : undefined;
-
- if (errorMessageSplit.length > 1) {
- fakeError.name = errorMessageSplit[0] + 'Error: ';
- }
- } catch {
-
- }
-
- const fakeErrorObject = JSON.parse(
- JSON.stringify(fakeError, Object.getOwnPropertyNames(fakeError))
- );
- return (
- <Format expandPaths={expandPaths} onExpand={onExpand} args={[fakeErrorObject]} />
- );
- }
- return (
- <Format
- expandPaths={expandPaths}
- onExpand={onExpand}
- args={args ?? [frame.message]}
- />
- );
- }
|