You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
The ExtraErrorData integration is not capturing nested error causes #15142
exportclassCustomErrorextendsError{// ... tell me if you need the whole class. But the point is, that this.cause is returned inside `toJSON`toJSON(): Record<string,unknown>{return{message: this.message,name: this.name,cause: this.cause,};}}
Steps to Reproduce
Set up a custom error class that has a toJSON method, which includes the this.cause property.
Throw an error which has such error in its cause. E.g.
I just tested this out and had a look at our code, indeed if cause is an Error or if a value of a property inside the JSON returned from toJSON is an Error it gets immediately serialized via toString regardless of having a toJSON itself.
This is something we can consider changing, I'll bring it up with the team. Otherwise, we also welcome contributions if you're interested.
Thanks for the quick response @andreiborza. Sounds good!
I fully expected the integration to walk through all the attributes up to the defined depth - and with captureErrorCause enabled, including the causes of all errors also being serialized.
Also, I want to mention that sometimes there's an error in the error stack that we have no control over (e.g. from a framework TRPCError for example). This error still might have an attribute like originalError or cause, letting us access our CustomError that holds important information about the context the exception occurred. But it does not have a toJSON method. It would be great if attributes of such errors, most importantly the cause, still can get walked through to actually reach the error with the most important context.
Edit: Regarding contributions - I'm not sure how, but I'm happy to assist.
@michaelschufi just a heads up, this is very low prio for us atm. I put it in the backlog but we might not get around to it in a while. We don't even have a good idea of how this should work tbh.
We are also interested in this setup. Our stack uses nested errors such as:
Error: fetching X failed <-- this error has no toJSON
at ...
Caused by: RequestError: Failed to fetch: X <-- this error has additional information about why the request failed
at ...
Caused by: TypeError: Failed to fetch
at FetchClient.fetch
In this case we would like to add a toJSON to our RequestError to attach additional information around what the response (if any) was, what the status code was etc.
We don't know how deep our RequestError will be in the cause structure (it could be top level, it could be 3 levels deep), which makes this difficult to work around.
Right now if it's not top level, the integration doesn't call the toJSON method loosing this information. This leads us to debug issues such as Request X failed with status code 500 and no other information around what else the server might've returned.
For now I was thinking of building a small integration myself that could deal with this and create a nested structure for this extra data by inspecting the errors within the cause chain and calling toJSON on every level.
I think building your own eventProcessor (addable via Sentry.addEventProcessor((...) => {...})) is a reasonable approach to unblock yourself until we get to this.
Activity
andreiborza commentedon Jan 23, 2025
Hi @michaelschufi, thanks for filing this.
I just tested this out and had a look at our code, indeed if
causeis anErroror if a value of a property inside the JSON returned fromtoJSONis an Error it gets immediately serialized viatoStringregardless of having atoJSONitself.This is something we can consider changing, I'll bring it up with the team. Otherwise, we also welcome contributions if you're interested.
michaelschufi commentedon Jan 24, 2025
Thanks for the quick response @andreiborza. Sounds good!
I fully expected the integration to walk through all the attributes up to the defined depth - and with
captureErrorCauseenabled, including the causes of all errors also being serialized.Also, I want to mention that sometimes there's an error in the error stack that we have no control over (e.g. from a framework
TRPCErrorfor example). This error still might have an attribute likeoriginalErrororcause, letting us access ourCustomErrorthat holds important information about the context the exception occurred. But it does not have atoJSONmethod. It would be great if attributes of such errors, most importantly thecause, still can get walked through to actually reach the error with the most important context.Edit: Regarding contributions - I'm not sure how, but I'm happy to assist.
andreiborza commentedon Jan 24, 2025
Thanks, we'll take a look at that too.
andreiborza commentedon Feb 6, 2025
@michaelschufi just a heads up, this is very low prio for us atm. I put it in the backlog but we might not get around to it in a while. We don't even have a good idea of how this should work tbh.
3 remaining items
IgnusG commentedon May 5, 2025
We are also interested in this setup. Our stack uses nested errors such as:
In this case we would like to add a
toJSONto ourRequestErrorto attach additional information around what the response (if any) was, what the status code was etc.We don't know how deep our
RequestErrorwill be in the cause structure (it could be top level, it could be 3 levels deep), which makes this difficult to work around.Right now if it's not top level, the integration doesn't call the
toJSONmethod loosing this information. This leads us to debug issues such asRequest X failed with status code 500and no other information around what else the server might've returned.For now I was thinking of building a small integration myself that could deal with this and create a nested structure for this extra data by inspecting the errors within the cause chain and calling
toJSONon every level.lforst commentedon May 5, 2025
I think building your own
eventProcessor(addable viaSentry.addEventProcessor((...) => {...})) is a reasonable approach to unblock yourself until we get to this.feat(core): better cause data extraction (#17375)
github-actions commentedon Aug 12, 2025
A PR closing this issue has just been released 🚀
This issue was referenced by PR #17375, which was included in the 10.5.0 release.