elastic / kibana

Your window into the Elastic Stack
https://www.elastic.co/products/kibana
Other
19.7k stars 8.12k forks source link

[Spacetime] Substitute type level error management in favor over try / catch control flow #188678

Open wayneseymour opened 1 month ago

wayneseymour commented 1 month ago

[DRAFT]

Summary

I dislike how try / catch is used for control flow logic, especially as JS / TS natively do not tell you at the type level, that this is the case: E.g.:

Screenshot 2024-07-18 at 16 49 16

As you can see, QuokkaJS knows at runtime this thunk is throwing, but as you can see in the pop-over, the type system only recongizes a thunk that returns void

Even after I've annotated it, the type system still is unaware of the exception

Screenshot 2024-07-18 at 16 59 51

FP-TS is widely used in our code base, including IO-TS.

Proposal

Build on top of what we have (TS + FP-TS), with future hopes of swapping in Effect in the future, maybe.

There are examples all over the code base, but many are embedded with business logic which makes it more difficult to re-use.

I built something before I came to elastic, that I actually use here, in the code coverage ingestion pipeline. I added this to our repo, before someone added FP-TS as a dependency.

Now, that I've seen more and more use of FP-TS, I think it's time to use it more.

My naive implementation, FP-TS and now Effect all use the same concept: lift values and even behaviours (functions) into a container (box) and then run computations on the value, via the container (box), and maybe even expose the innards especially when the box needs to interact with vanilla js.

Goals

elasticmachine commented 1 month ago

Pinging @elastic/appex-qa (Team:QA)