-
Notifications
You must be signed in to change notification settings - Fork 696
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
Conversation
There was a problem hiding this 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) |
There was a problem hiding this comment.
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. ;)
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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)
Thanks for the comments. Addressed 'em all. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
@Mergifyio rebase master |
✅ Branch has been successfully rebased |
324f2d2
to
c584327
Compare
@Mergifyio rebase |
☑️ Nothing to do
|
CI jobs are stuck, so let me merge manually. |
* don't crash on a few stray exceptions * try -> catch and display * act on reviewer comments Co-authored-by: Gershom Bazerman <[email protected]>
* don't crash on a few stray exceptions * try -> catch and display * act on reviewer comments Co-authored-by: Gershom Bazerman <[email protected]>
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