lwt icon indicating copy to clipboard operation
lwt copied to clipboard

More raise less fail

Open raphael-proust opened this issue 2 years ago • 1 comments

raise and reraise are "better" than fail for backtracing and such

raphael-proust avatar Feb 07 '24 10:02 raphael-proust

Is that documented in the manual/docs? Should code using Lwt switch to raise/reraise?

MisterDA avatar Jun 20 '24 07:06 MisterDA

Is that documented in the manual/docs? Should code using Lwt switch to raise/reraise?

reraise is documented in the doc https://github.com/ocsigen/lwt/blob/master/src/core/lwt.mli#L581 / https://ocaml.org/p/lwt/latest/doc/Lwt/index.html#val-reraise

and it is recommended to use in the documentation of catch and try_bind.

The use of raise (instead of fail) is recommended in the documentation of fail and has been for quite some time now: https://github.com/ocsigen/lwt/blob/master/src/core/lwt.mli#L453 / https://ocaml.org/p/lwt/latest/doc/Lwt/index.html#val-fail

Use Lwt.fail only when you specifically want to create a rejected promise, to pass to another function, or store in a data structure.


Note that it's better for users to use raise+reraise, but ultimately, even if they use fail this PR does not affect them negatively.

raphael-proust avatar Aug 02 '24 17:08 raphael-proust