Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Raise and reraise exceptions with Stdlib rather than Lwt#1079

Merged
rgrinberg merged 3 commits intomirage:masterfrom
MisterDA:lwt-exceptions
Aug 30, 2024
Merged

Raise and reraise exceptions with Stdlib rather than Lwt#1079
rgrinberg merged 3 commits intomirage:masterfrom
MisterDA:lwt-exceptions

Conversation

@MisterDA
Copy link
Contributor

Lwt's documentation reads:

In most cases, it is better to use failwith s from the standard
library.

and

Whenever possible, it is recommended to use raise exn instead, as
raise captures a backtrace, while Lwt.fail does not. If you call
raise exn in a callback that is expected by Lwt to return a
promise, Lwt will automatically wrap exn in a rejected promise,
but the backtrace will have been recorded by the OCaml runtime.

For example, bind's second argument is a callback which returns a
promise. And so it is recommended to use raise in the body of that
callback.

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

Prefer to capture backtraces to improve debugability.

See also ocsigen/lwt#1008 and mirage/ocaml-conduit#430.

MisterDA added 3 commits July 22, 2024 16:54
Lwt's documentation reads:

> In most cases, it is better to use `failwith s` from the standard
> library.

and

> Whenever possible, it is recommended to use `raise exn` instead, as
> raise captures a backtrace, while `Lwt.fail` does not. If you call
> `raise exn` in a callback that is expected by Lwt to return a
> promise, Lwt will automatically wrap `exn` in a rejected promise,
> but the backtrace will have been recorded by the OCaml runtime.
>
> For example, `bind`'s second argument is a callback which returns a
> promise. And so it is recommended to use `raise` in the body of that
> callback.
>
> Use `Lwt.fail` only when you specifically want to create a rejected
> promise, to pass to another function, or store in a data structure.

Prefer to capture backtraces to improve debugability.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants