opam icon indicating copy to clipboard operation
opam copied to clipboard

Rework download failures for better error reporting

Open Keryan-dev opened this issue 1 year ago • 1 comments

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

Keryan-dev avatar Jul 18 '24 14:07 Keryan-dev

Trimmed up, and undrafted.

Some tests changes, still not ideal but there should be no loss of information.

Keryan-dev avatar Jul 23 '24 10:07 Keryan-dev

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).

leviroth avatar Oct 27 '24 20:10 leviroth