ui: Display hints to resolve profile collisions.

Fixes <https://bugs.gnu.org/29255>.
Reported by Ben Sturmfels <ben@sturm.com.au>.

* guix/ui.scm (display-collision-resolution-hint): New procedure.
(call-with-error-handling): Call it upon '&profile-collistion-error'.
This commit is contained in:
Ludovic Courtès 2017-12-10 23:41:21 +01:00
parent 8bc1935c7c
commit 3b80b81358
No known key found for this signature in database
GPG key ID: 090B11993D9AEBB5

View file

@ -502,6 +502,26 @@ (define unit
(x (x
(leave (G_ "unknown unit: ~a~%") unit))))))) (leave (G_ "unknown unit: ~a~%") unit)))))))
(define (display-collision-resolution-hint collision)
"Display hints on how to resolve COLLISION, a &profile-collistion-error."
(define (top-most-entry entry)
(let loop ((entry entry))
(match (force (manifest-entry-parent entry))
(#f entry)
(parent (loop parent)))))
(let* ((first (profile-collision-error-entry collision))
(second (profile-collision-error-conflict collision))
(name1 (manifest-entry-name (top-most-entry first)))
(name2 (manifest-entry-name (top-most-entry second))))
(if (string=? name1 name2)
(display-hint (format #f (G_ "You cannot have two different versions
or variants of @code{~a} in the same profile.")
name1))
(display-hint (format #f (G_ "Try upgrading both @code{~a} and @code{~a},
or remove one of them from the profile.")
name1 name2)))))
(define (call-with-error-handling thunk) (define (call-with-error-handling thunk)
"Call THUNK within a user-friendly error handler." "Call THUNK within a user-friendly error handler."
(define (port-filename* port) (define (port-filename* port)
@ -570,6 +590,7 @@ (define (manifest-entry-output* entry)
(manifest-entry-output* conflict) (manifest-entry-output* conflict)
(manifest-entry-item conflict)) (manifest-entry-item conflict))
(report-parent-entries conflict) (report-parent-entries conflict)
(display-collision-resolution-hint c)
(exit 1))) (exit 1)))
((nar-error? c) ((nar-error? c)
(let ((file (nar-error-file c)) (let ((file (nar-error-file c))