Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify IO errors as Eio.Io #378

Merged
merged 1 commit into from
Dec 5, 2022
Merged

Unify IO errors as Eio.Io #378

merged 1 commit into from
Dec 5, 2022

Conversation

talex5
Copy link
Collaborator

@talex5 talex5 commented Dec 1, 2022

This makes it easy to catch and log all IO errors if desired. The exception payload gives the type and can be used for matching specific errors. It also allows attaching extra information to exceptions.

Example of a new-style error message:

Eio.Io Net Connection_failure Timeout,
  connecting to tcp:127.0.0.1:80,
  connecting to "example.com":http,
  fetching http://example.com/index.html

When multiple exceptions occur, we now keep and report all the backtraces. If multiple IO exceptions occur, the result is also an IO exception (so you can still catch all IO errors).

Various functions now add extra context to IO exceptions:

  • accept_fork adds the remote address.
  • Various functions add their arguments (Net.connect, Path.load, etc).

Also:

  • Eio_linux.openfile is gone (was just a hack for testing in the early days).

  • connect functions no longer need to wrap all errors in Connection_failure. The fact you got an IO error from connect is enough.

@talex5 talex5 force-pushed the errors branch 6 times, most recently from 0010c42 to 4305876 Compare December 1, 2022 15:16
This makes it easy to catch and log all IO errors if desired. The
exception payload gives the type and can be used for matching specific
errors. It also allows attaching extra information to exceptions.

When multiple exceptions occur, we now keep and report all the backtraces.
If multiple IO exceptions occur, the result is also an IO exception (so
you can still catch all IO errors).

Various functions now add extra context to IO exceptions:
- `accept_fork` adds the remote address.
- Various functions add their arguments (`Net.connect`, `Path.load`, etc).

Also:

- `Eio_linux.openfile` is gone (was just a hack for testing in the early
  days).

- `connect` functions no longer need to wrap all errors in
  `Connection_failure`. The fact you got an IO error from `connect` is
  enough.

- Fixed non-tail-recursive continue in Eio_luv (`Socket_of_fd`).
@talex5 talex5 requested a review from haesbaert December 2, 2022 10:38
@talex5 talex5 merged commit a17ec44 into ocaml-multicore:main Dec 5, 2022
@talex5 talex5 deleted the errors branch December 5, 2022 13:03
talex5 added a commit to talex5/opam-repository that referenced this pull request Dec 7, 2022
CHANGES:

API changes:

- Unify IO errors as `Eio.Io` (@talex5 ocaml-multicore/eio#378).
  This makes it easy to catch and log all IO errors if desired.
  The exception payload gives the type and can be used for matching specific errors.
  It also allows attaching extra information to exceptions, and various functions were updated to do this.

- Add `Time.Mono` for monotonic clocks (@bikallem @talex5 ocaml-multicore/eio#338).
  Using the system clock for timeouts, etc can fail if the system time is changed during the wait.

- Allow datagram sockets to be created without a source address (@bikallem @haesbaert ocaml-multicore/eio#360).
  The kernel will allocate an address in this case.
  You can also now control the `reuse_addr` and `reuse_port` options.

- Add `File.stat` and improve `Path.load` (@haesbaert @talex5 ocaml-multicore/eio#339).
  `Path.load` now uses the file size as the initial buffer size.

- Add `Eio_unix.pipe` (@patricoferris ocaml-multicore/eio#350).
  This replaces `Eio_linux.pipe`.

- Avoid short reads from `getrandom(2)` (@haesbaert ocaml-multicore/eio#344).
  Guards against buggy user code that might not handle this correctly.

- Rename `Flow.read` to `Flow.single_read` (@talex5 ocaml-multicore/eio#353).
  This is a low-level function and it is easy to use it incorrectly by ignoring the possibility of short reads.

Bug fixes:

- Eio_luv: Fix non-tail-recursive continue (@talex5 ocaml-multicore/eio#378).
  Affects the `Socket_of_fd` and `Socketpair` effects.

- Eio_linux: UDP sockets were not created close-on-exec (@talex5 ocaml-multicore/eio#360).

- Eio_linux: work around io_uring non-blocking bug (@haesbaert ocaml-multicore/eio#327 ocaml-multicore/eio#355).
  The proper fix should be in Linux 6.1.

- `Eio_mock.Backend`: preserve backtraces from `main` (@talex5 ocaml-multicore/eio#349).

- Don't lose backtrace in `Switch.run_internal` (@talex5 ocaml-multicore/eio#369).

Documentation:

- Use a proper HTTP response in the README example (@talex5 ocaml-multicore/eio#377).

- Document that read_dir excludes "." and ".." (@talex5 ocaml-multicore/eio#379).

- Warn about both operations succeeding in `Fiber.first` (@talex5 ocaml-multicore/eio#358, reported by @iitalics).

- Update README for OCaml 5.0.0~beta2 (@talex5 ocaml-multicore/eio#375).

Backend-specific changes:

- Eio_luv: add low-level process support (@patricoferris ocaml-multicore/eio#359).
  A future release will add Eio_linux support and a cross-platform API for this.

- Expose `Eio_luv.Low_level.Stream.write` (@patricoferris ocaml-multicore/eio#359).

- Expose `Eio_luv.Low_level.get_loop` (@talex5 ocaml-multicore/eio#371).
  This is needed if you want to create resources directly and then use them with Eio_luv.

- `Eio_linux.Low_level.openfile` is gone (@talex5 ocaml-multicore/eio#378).
  It was just left-over test code.
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.

1 participant