fix(cli): retry on failure to clone packages (or abort)
Something often reported are file-missing errors when a package that should be present isn't. This can easily happen if, say, during a 'doom sync' or 'doom upgrade' a package fails to clone correctly and the user misses the errors, then tries to carry on as normal. What's worse is that Straight leaves behind an empty directory, which it treats as a sign that the package has been cloned correctly, so it doesn't raise any fuss over them. With this change, 'doom sync' (and 'doom upgrade') will now try again, if the clone process fails the first time (up to 3 times) before aborting the whole process altogether, which should be loud enough for users not to miss. Note that these failures at 99.99% because of network (or upstream downtime) issues. For now, this does leave Doom in an incomplete state (until you try again when the connection issue is resolved), but a rollback step will be added in v3 to prevent this, as well as better error messages (as well as @doomelpa mirror for packages on less reliable hosts, like codeberg, savannah, etc).
This commit is contained in:
parent
63c470bff3
commit
1fa8d3a4b9
1 changed files with 36 additions and 20 deletions
|
@ -283,7 +283,8 @@ declaration) or dependency thereof that hasn't already been."
|
||||||
(if-let (built
|
(if-let (built
|
||||||
(doom-packages--with-recipes (doom-package-recipe-list)
|
(doom-packages--with-recipes (doom-package-recipe-list)
|
||||||
(recipe package type local-repo)
|
(recipe package type local-repo)
|
||||||
(unless (file-directory-p (straight--repos-dir local-repo))
|
(let ((repo-dir (straight--repos-dir local-repo)))
|
||||||
|
(unless (file-directory-p repo-dir)
|
||||||
(doom-packages--cli-recipes-update))
|
(doom-packages--cli-recipes-update))
|
||||||
(condition-case-unless-debug e
|
(condition-case-unless-debug e
|
||||||
(let ((straight-use-package-pre-build-functions
|
(let ((straight-use-package-pre-build-functions
|
||||||
|
@ -291,18 +292,33 @@ declaration) or dependency thereof that hasn't already been."
|
||||||
(when-let (commit (cdr (assoc pkg pinned)))
|
(when-let (commit (cdr (assoc pkg pinned)))
|
||||||
(print! (item "Checked out %s: %s") pkg commit)))
|
(print! (item "Checked out %s: %s") pkg commit)))
|
||||||
straight-use-package-pre-build-functions)))
|
straight-use-package-pre-build-functions)))
|
||||||
|
;; HACK: Straight can sometimes fail to clone a repo,
|
||||||
|
;; leaving behind an empty directory which, in future
|
||||||
|
;; invocations, it will assume indicates a successful
|
||||||
|
;; clone (causing load errors later).
|
||||||
|
(let ((try 0))
|
||||||
|
(while (or (not (file-directory-p repo-dir))
|
||||||
|
(directory-empty-p repo-dir))
|
||||||
|
(if (= try 3)
|
||||||
|
(error "Failed to clone package")
|
||||||
|
(when (> try 0)
|
||||||
|
(print! "Failed to clone %S, trying again (attempt #%d)..." package (1+ try))))
|
||||||
|
(delete-file (file-name-concat (straight--modified-dir) package))
|
||||||
|
(delete-directory repo-dir t)
|
||||||
|
(delete-directory (straight--build-dir package) t)
|
||||||
(straight-use-package (intern package))
|
(straight-use-package (intern package))
|
||||||
;; HACK Line encoding issues can plague repos with dirty
|
(cl-incf try)))
|
||||||
;; worktree prompts when updating packages or "Local
|
;; HACK: Line encoding issues can plague repos with
|
||||||
;; variables entry is missing the suffix" errors when
|
;; dirty worktree prompts when updating packages or
|
||||||
;; installing them (see hlissner/doom-emacs#2637), so
|
;; "Local variables entry is missing the suffix"
|
||||||
;; have git handle conversion by force.
|
;; errors when installing them (see #2637), so have
|
||||||
|
;; git handle conversion by force.
|
||||||
(when (and doom--system-windows-p (stringp local-repo))
|
(when (and doom--system-windows-p (stringp local-repo))
|
||||||
(let ((default-directory (straight--repos-dir local-repo)))
|
(let ((default-directory (straight--repos-dir local-repo)))
|
||||||
(when (file-in-directory-p default-directory straight-base-dir)
|
(when (file-in-directory-p default-directory straight-base-dir)
|
||||||
(straight--process-run "git" "config" "core.autocrlf" "true")))))
|
(straight--process-run "git" "config" "core.autocrlf" "true")))))
|
||||||
(error
|
(error
|
||||||
(signal 'doom-package-error (list package e))))))
|
(signal 'doom-package-error (list package e)))))))
|
||||||
(progn
|
(progn
|
||||||
(when (featurep 'native-compile)
|
(when (featurep 'native-compile)
|
||||||
(doom-packages--compile-site-files)
|
(doom-packages--compile-site-files)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue