Motivation
Why ?
Error management in JS/TS is difficult, to overcome this we created our own structure inspired by Rust's error management.
But that's not enough. Managing a bunch of packages and their errors becomes very difficult at some point. This is exactly why we are coming to a point where we cannot trust js stack trace. We believe that in projects where many people work, it will be much more beneficial for us to make small performance sacrifices in order to make the code easier to debug.
The solution we implemented to achieve this is to create a custom error type like this (this is an oversimplified version of the codebase)
There must be a causal chain for errors.
Now we can combine it with neverthrow to achieve the desired result.
*1 -> https://www.typescriptlang.org/docs/handbook/2/narrowing.html#truthiness-narrowing
As seen in the example, errors reached us with the cause chain and correct types.
Normally tags should be defined separately. If you don't want to deal with this you can prefix it with a question mark (?
)