Handling 'nested errors' in TypeScript

What's a good method for dealing with "nested errors"? Right now I do this:

export const ErrorCommonSchema = {
    report: S.optional(S.Boolean),
    cause: S.optional(S.Any),
    message: S.optional(S.String),
    extra: S.optional(S.Record(S.String, S.Any)),
    severity: S.optional(ErrorSeveritySchema)
}
export class SocialLoginError extends S.TaggedError<SocialLoginError>()("SocialLoginError", {
    ...ErrorCommonSchema,
    loginType: S.Literal("google", "facebook", "apple")
}) {}

I use these to get typed errors from non effect apis, ex:

Effect.tryPromise({
    try: () => {}//...whatever
    catch: e => new SocialLoginError({message: `error signing in`, cause: e, loginType: 'google'})
})


The problem with this is that when I log an error via Cause.pretty the underlying error with the useful information (in the cause field of the failure) doesn't get printed.

A reason I do it this way is so I can get good traces in Sentry. It will recursively read Error.cause which is a convention supported by browsers

Is there a better pattern for dealing with "nested errors" like this? I could manually unpack everything in my logger but I wanted to check if I missed a better way to handle the nesting of errors that naturally occurs when capturing non-effect errors as tagged effect failures.
Was this page helpful?