From d5e9abb0395a21e79d4f77181597103d4daf138c Mon Sep 17 00:00:00 2001 From: Alex Kost Date: Wed, 8 Oct 2014 00:32:28 +0400 Subject: [PATCH 1/3] profiles: Add condition types for profile and generation. * guix/profiles.scm (&profile-error, &generation-error): New condition types. * guix/ui.scm (call-with-error-handling): Handle these types. * guix/scripts/package.scm (roll-back, guix-package): Raise '&profile-error' where needed. --- guix/profiles.scm | 24 +++++++++++++++++++++++- guix/scripts/package.scm | 15 +++++++-------- guix/ui.scm | 7 +++++++ 3 files changed, 37 insertions(+), 9 deletions(-) diff --git a/guix/profiles.scm b/guix/profiles.scm index 18733a6..0e19d7a 100644 --- a/guix/profiles.scm +++ b/guix/profiles.scm @@ -35,7 +35,16 @@ #:use-module (srfi srfi-11) #:use-module (srfi srfi-19) #:use-module (srfi srfi-26) - #:export (manifest make-manifest + #:use-module (srfi srfi-34) + #:use-module (srfi srfi-35) + #:export (&profile-error + profile-error? + profile-error-profile + &generation-error + generation-error? + generation-error-generation + + manifest make-manifest manifest? manifest-entries @@ -84,6 +93,19 @@ ;;; +;;; Condition types. +;;; + +(define-condition-type &profile-error &error + profile-error? + (profile profile-error-profile)) + +(define-condition-type &generation-error &error + generation-error? + (generation generation-error-generation)) + + +;;; ;;; Manifests. ;;; diff --git a/guix/scripts/package.scm b/guix/scripts/package.scm index fc9c37b..7e2143c 100644 --- a/guix/scripts/package.scm +++ b/guix/scripts/package.scm @@ -38,6 +38,8 @@ #:use-module (srfi srfi-11) #:use-module (srfi srfi-19) #:use-module (srfi srfi-26) + #:use-module (srfi srfi-34) + #:use-module (srfi srfi-35) #:use-module (srfi srfi-37) #:use-module (gnu packages) #:use-module (gnu packages base) @@ -109,8 +111,7 @@ return PROFILE unchanged. The goal is to treat '-p ~/.guix-profile' as if (previous-number (previous-generation-number profile number)) (previous-generation (generation-file-name profile previous-number))) (cond ((not (file-exists? profile)) ; invalid profile - (leave (_ "profile '~a' does not exist~%") - profile)) + (raise (condition (&profile-error (profile profile))))) ((zero? number) ; empty profile (format (current-error-port) (_ "nothing to do: already at the empty profile~%"))) @@ -723,8 +724,7 @@ more information.~%")) (match-lambda (('delete-generations . pattern) (cond ((not (file-exists? profile)) ; XXX: race condition - (leave (_ "profile '~a' does not exist~%") - profile)) + (raise (condition (&profile-error (profile profile))))) ((string-null? pattern) (delete-generations (%store) profile @@ -833,8 +833,7 @@ more information.~%")) (newline))) (cond ((not (file-exists? profile)) ; XXX: race condition - (leave (_ "profile '~a' does not exist~%") - profile)) + (raise (condition (&profile-error (profile profile))))) ((string-null? pattern) (for-each list-generation (profile-generations profile))) ((matching-generations pattern profile) @@ -915,8 +914,8 @@ more information.~%")) (_ #f)))) (let ((opts (parse-options))) - (or (process-query opts) - (with-error-handling + (with-error-handling + (or (process-query opts) (parameterize ((%store (open-connection))) (set-build-options-from-command-line (%store) opts) diff --git a/guix/ui.scm b/guix/ui.scm index 04345d4..9c0a5d2 100644 --- a/guix/ui.scm +++ b/guix/ui.scm @@ -23,6 +23,7 @@ #:use-module (guix store) #:use-module (guix config) #:use-module (guix packages) + #:use-module (guix profiles) #:use-module (guix build-system) #:use-module (guix derivations) #:use-module ((guix build utils) #:select (mkdir-p)) @@ -229,6 +230,12 @@ interpreted." (location->string loc) (package-full-name package) (build-system-name system)))) + ((profile-error? c) + (leave (_ "profile '~a' does not exist~%") + (profile-error-profile c))) + ((generation-error? c) + (leave (_ "generation '~a' does not exist~%") + (generation-error-generation c))) ((nix-connection-error? c) (leave (_ "failed to connect to `~a': ~a~%") (nix-connection-error-file c) -- 2.1.2