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

Better recovery from a few index/tar errors #7972

Merged
merged 3 commits into from
Feb 23, 2022
Merged

Conversation

gbaz
Copy link
Collaborator

@gbaz gbaz commented Feb 12, 2022

Resolves #5518 and #4987

Both these errors are in theory non-fatal, but simply gave uncaught exceptions. Cabal now warns on the exceptions and continues. This improves the resilience of cabal to bad cached index state from remote repositories, but does not solve the general problem completely. The most general path is to implement haskell/hackage-security#199

Copy link
Member

@Mikolaj Mikolaj left a comment

Choose a reason for hiding this comment

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

Makes sense.

@@ -365,7 +365,8 @@ readRepoIndex :: Verbosity -> RepoContext -> Repo -> RepoIndexState
readRepoIndex verbosity repoCtxt repo idxState =
handleNotFound $ do
when (isRepoRemote repo) $ warnIfIndexIsOld =<< getIndexFileAge repo
updateRepoIndexCache verbosity (RepoIndex repoCtxt repo)
-- note that if this step fails due to a bad repocache, the the procedure can still succeed by reading from the existing cache, which is updated regardless.
updateRepoIndexCache verbosity (RepoIndex repoCtxt repo) `catch` (\(e :: SomeException) -> warn verbosity $ "unable to update the repo index cache -- " ++ displayException e)
Copy link
Member

Choose a reason for hiding this comment

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

Would it be possible to make this line a bit shorter? Even github forces me to scroll to see it. ;)

Copy link
Collaborator

Choose a reason for hiding this comment

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

+1, also let's consistently use show or displayException? (unless there's a particular reason for the distinction I'm missing)

@@ -209,7 +211,7 @@ updateRepo verbosity _updateFlags repoCtxt (repo, indexState) = do
case updated of
Sec.NoUpdates -> do
now <- getCurrentTime
setModificationTime (indexBaseName repo <.> "tar") now
setModificationTime (indexBaseName repo <.> "tar") now `catch` (\(e :: SomeException) -> warn verbosity $ "Could not set modification time of index tarball -- " ++ show e)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This also catches asynchronous exceptions, such as e.g. UserInterrupt issued when Ctrl-C is hit; would be more robust to use safe-exception's catch or catch some more targeted set of exceptions, e.g. using catchIO as below.

else ioError e
else do
putStrLn $ "Warning: could not read current index timestamp: " ++ show e
return Nothing
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we pass in verbosity and also use warn here?

@@ -365,7 +365,8 @@ readRepoIndex :: Verbosity -> RepoContext -> Repo -> RepoIndexState
readRepoIndex verbosity repoCtxt repo idxState =
handleNotFound $ do
when (isRepoRemote repo) $ warnIfIndexIsOld =<< getIndexFileAge repo
updateRepoIndexCache verbosity (RepoIndex repoCtxt repo)
-- note that if this step fails due to a bad repocache, the the procedure can still succeed by reading from the existing cache, which is updated regardless.
updateRepoIndexCache verbosity (RepoIndex repoCtxt repo) `catch` (\(e :: SomeException) -> warn verbosity $ "unable to update the repo index cache -- " ++ displayException e)
Copy link
Collaborator

Choose a reason for hiding this comment

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

+1, also let's consistently use show or displayException? (unless there's a particular reason for the distinction I'm missing)

@gbaz
Copy link
Collaborator Author

gbaz commented Feb 22, 2022

Thanks for the comments. Addressed 'em all.

Copy link
Collaborator

@robx robx left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@Mikolaj Mikolaj added merge me Tell Mergify Bot to merge squash+merge me Tell Mergify Bot to squash-merge and removed merge me Tell Mergify Bot to merge labels Feb 22, 2022
@jneira
Copy link
Member

jneira commented Feb 22, 2022

@Mergifyio rebase master

@mergify
Copy link
Contributor

mergify bot commented Feb 22, 2022

rebase master

✅ Branch has been successfully rebased

@jneira jneira force-pushed the gb/recover-some-tar-errors branch from 324f2d2 to c584327 Compare February 22, 2022 20:31
@Mikolaj
Copy link
Member

Mikolaj commented Feb 23, 2022

@Mergifyio rebase

@mergify
Copy link
Contributor

mergify bot commented Feb 23, 2022

rebase

☑️ Nothing to do

  • -closed [:pushpin: rebase requirement]
  • #commits-behind>0 [:pushpin: rebase requirement]

@Mikolaj
Copy link
Member

Mikolaj commented Feb 23, 2022

CI jobs are stuck, so let me merge manually.

@Mikolaj Mikolaj merged commit e5dc4dd into master Feb 23, 2022
Kleidukos pushed a commit to Kleidukos/cabal that referenced this pull request Mar 30, 2022
* don't crash on a few stray exceptions

* try -> catch and display

* act on reviewer comments

Co-authored-by: Gershom Bazerman <[email protected]>
andreabedini pushed a commit to andreabedini/cabal that referenced this pull request May 5, 2022
* don't crash on a few stray exceptions

* try -> catch and display

* act on reviewer comments

Co-authored-by: Gershom Bazerman <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
attention: needs-review squash+merge me Tell Mergify Bot to squash-merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"truncated tar archive" on cabal update
4 participants