MCPcopy Index your code
hub / github.com/getsentry/sentry-javascript / getMessageForObject

Function getMessageForObject

packages/core/src/utils/eventbuilder.ts:75–101  ·  view source on GitHub ↗
(exception: Record<string, unknown>)

Source from the content-addressed store, hash-verified

73}
74
75function getMessageForObject(exception: Record<string, unknown>): string {
76 if ('name' in exception && typeof exception.name === 'string') {
77 let message = `'${exception.name}' captured as exception`;
78
79 if ('message' in exception && typeof exception.message === 'string') {
80 message += ` with message '${exception.message}'`;
81 }
82
83 return message;
84 } else if ('message' in exception && typeof exception.message === 'string') {
85 return exception.message;
86 }
87
88 const keys = extractExceptionKeysForMessage(exception);
89
90 // Some ErrorEvent instances do not have an `error` property, which is why they are not handled before
91 // We still want to try to get a decent message for these cases
92 if (isErrorEvent(exception)) {
93 return `Event \`ErrorEvent\` captured as exception with message \`${exception.message}\``;
94 }
95
96 const className = getObjectClassName(exception);
97
98 return `${
99 className && className !== 'Object' ? `'${className}'` : 'Object'
100 } captured as exception with keys: ${keys}`;
101}
102
103function getObjectClassName(obj: unknown): string | undefined | void {
104 try {

Callers 1

getExceptionFunction · 0.85

Calls 3

isErrorEventFunction · 0.90
getObjectClassNameFunction · 0.70

Tested by

no test coverage detected