opam
opam copied to clipboard
Rework download failures for better error reporting
Early WIP for eventual discussions.
General wishlist so far:
- Better early error diagnostic
- Reduce generic error format uses to a minimum
- Eliminate raw exception printing in error messages
- Eliminate assumptions about error string content
Trimmed up, and undrafted.
Some tests changes, still not ideal but there should be no loss of information.
I found a case where this change makes the error considerably less descriptive:
# On opam 2.2.1
$ opam repository add example http://example.com
[ERROR] Could not update repository "example": OpamDownload.Download_fail(_, "curl: code 404 while downloading http://example.com/index.tar.gz")
[ERROR] Initial repository fetch failed
# On this branch
$ dune exec src/client/opamMain.exe -- repository add example http://example.com
[ERROR] Could not update repository "example": OpamDownload.Download_fail(_)
[ERROR] Initial repository fetch failed
I believe the issue arises because of the use of Printexc.to_string in various places. As I understand it, the default exception printer is unable to represent variants with arguments. Thus, changing an exception like Download_fail of string option * string into Download_fail of dl_failure means that none of the error description can be rendered by Printexc (as, indeed, the first argument is currently not rendered).