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

Rework download failures for better error reporting #6107

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

Keryan-dev
Copy link
Collaborator

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

Copy link
Member

@kit-ty-kate kit-ty-kate left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apart from the one suggestion, the design looks great

src/format/opamTypes.mli Outdated Show resolved Hide resolved
@Keryan-dev
Copy link
Collaborator Author

Trimmed up, and undrafted.

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

@Keryan-dev Keryan-dev marked this pull request as ready for review July 23, 2024 10:15
Copy link
Member

@kit-ty-kate kit-ty-kate left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM as a first step

src/repository/opamDownload.ml Outdated Show resolved Hide resolved
src/client/opamAction.ml Outdated Show resolved Hide resolved
Copy link
Member

@kit-ty-kate kit-ty-kate left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd recommend to avoid opens.
They make the codebase harder to maintain, read and reason about.

src/client/opamAdminCommand.ml Outdated Show resolved Hide resolved
src/client/opamAdminCommand.ml Outdated Show resolved Hide resolved
@kit-ty-kate kit-ty-kate self-requested a review July 24, 2024 14:22
@kit-ty-kate kit-ty-kate marked this pull request as draft July 24, 2024 20:14
@@ -583,7 +583,7 @@ The following actions will be performed:
got md5=hash
[ERROR] Failed to get extra source "i-am-a-patch" of multiple-md5.1: Checksum mismatch

OpamSolution.Fetch_fail("Checksum mismatch")
Checksum mismatch
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this message feels redundant with the ones above

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In what way ? The lack of information should be the object of a patch for checksum related errors.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
[ERROR] multiple-md5.1/i-am-a-patch: Checksum mismatch for file://${BASEDIR}/p.patch:
          expected md5=hash
          got      md5=hash
[ERROR] Failed to get extra source "i-am-a-patch" of multiple-md5.1: Checksum mismatch

Checksum mismatch

"checksum mismatch" is displayed three times one after the other.

I believe the difference is that both errors above are displayed as the error happens and the last one is displayed when the actions finished.

Since this PR is no longer just an API improvement, i think it would be nicer to make it so that such redundant error messages are squashed into one

@@ -230,6 +230,8 @@ let display_error (n, error) =
| Sys.Break | OpamParallel.Aborted -> ()
| Failure s -> disp "%s" s
| OpamSystem.Process_error e -> disp "%s" (OpamProcess.string_of_result e)
| Fetch_fail failure ->
disp "%s" (get_dl_failure_reason failure).long_reason
| e ->
disp "%s" (Printexc.to_string e);
if OpamConsole.debug () then
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't find out why, but it appears that OpamConsole.header_error does not actually display the header like it should in the reftests. This is why some errors seem to appear without context.

@kit-ty-kate kit-ty-kate removed this from the 2.3.0~alpha milestone Jul 26, 2024
@kit-ty-kate kit-ty-kate added this to the 2.4.0~alpha1 milestone Sep 25, 2024
@leviroth
Copy link

leviroth commented Oct 27, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants