1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- import {memo} from 'react';
- import isObject from 'lodash/isObject';
- import {OnExpandCallback} from 'sentry/components/objectInspector';
- import {objectIsEmpty} 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';
- interface Props {
- frame: BreadcrumbFrame;
- expandPaths?: string[];
- onExpand?: OnExpandCallback;
- }
- function isSerializedError(frame: ConsoleFrame) {
- const args = frame.data.arguments;
- return (
- frame.message &&
- typeof frame.message === 'string' &&
- Array.isArray(args) &&
- args.length <= 2 &&
- isObject(args[0]) &&
- objectIsEmpty(args[0])
- );
- }
- function UnmemoizedMessageFormatter({frame, expandPaths, onExpand}: Props) {
- if (!isConsoleFrame(frame)) {
- return (
- <Format
- expandPaths={expandPaths}
- onExpand={onExpand}
- args={[frame.category, frame.data]}
- />
- );
- }
- 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 {
-
- }
- return <Format expandPaths={expandPaths} onExpand={onExpand} args={[fakeError]} />;
- }
- return (
- <Format
- expandPaths={expandPaths}
- onExpand={onExpand}
- args={args ?? [frame.message]}
- />
- );
- }
- const MessageFormatter = memo(UnmemoizedMessageFormatter);
- export default MessageFormatter;
|