Issue
In the JavaScript SDK, I'm getting unknown events titled "Object captured as exception with keys: ..." with no stack trace and little information. These come from a non-error object (a plain object) being thrown or passed to captureException.
Applies To
All SaaS Customers and Self-Hosted Users
JavaScript SDK (including React Native and other JavaScript-based SDKs)
Resolution
The JavaScript SDK creates this event when a non-error value, such as a plain object, is thrown or passed to Sentry.captureException() instead of an Error. Because the value is not an Error, the SDK cannot derive a stack trace, so it builds the title from the object's own keys to help you locate the source. For example:
const nonErrorObject = {
keys: "lost",
foo: "bar",
details: "unremarkable",
};
Sentry.captureException(nonErrorObject);
// or
throw nonErrorObject;
This is expected behavior. To resolve it, choose one of the following:
Capture an
Errorinstead (recommended). Find where the non-error object is thrown or captured, and pass anErrorinstance so the event gets a stack trace and groups correctly:Sentry.captureException(new Error("Descriptive message"));Filter the events if they are expected and you cannot change the source. Add the message to
ignoreErrors:ignoreErrors: ["Object captured as exception"];
For other ways to filter events, see the JavaScript filtering documentation.
