How to extract the root cause from nested errors in sql-drizzle using Effect Typescript

I am using sql-drizzle and having some issues with properly exposing the "most pertinent" error. For example, I had an issue in my schema where I was trying to insert floating point numbers into an integer column. The error that is surfaced in this case is an SqlError, whose cause is a DrizzleQueryError, whose cause is apparently a FiberFailure which wraps(?) another SqlError, whose cause is then the PostgresError which finally tells me the actual error that I'm interested in. I've tried various methods like tapErrorCause + Cause.squash and even writing my own recursive function to dig out the error, but once I reach the FiberFailure case, doing foo.toJSON() gives me a JSON object which clearly contains a cause, but foo.cause is undefined.

What is the correct way to flatten/traverse these sort of errors so that I can actually arrive at the root cause?
Was this page helpful?