mirror of
https://git.in.rschanz.org/ryan77627/guix.git
synced 2024-12-24 05:18:07 -05:00
store: Raise error conditions upon protocol errors.
* guix/store.scm (&nix-error, &nix-protocol-error): New SRFI-35 condition types. (process-stderr): Raise an error condition upon protocol errors instead of returning to the caller. This allows the connection to be reused for further interactions.
This commit is contained in:
parent
e3deeebb27
commit
e87088c9d5
1 changed files with 21 additions and 4 deletions
|
@ -22,6 +22,8 @@ (define-module (guix store)
|
|||
#:use-module (srfi srfi-1)
|
||||
#:use-module (srfi srfi-9)
|
||||
#:use-module (srfi srfi-26)
|
||||
#:use-module (srfi srfi-34)
|
||||
#:use-module (srfi srfi-35)
|
||||
#:use-module (ice-9 match)
|
||||
#:use-module (ice-9 rdelim)
|
||||
#:export (nix-server?
|
||||
|
@ -29,6 +31,11 @@ (define-module (guix store)
|
|||
nix-server-minor-version
|
||||
nix-server-socket
|
||||
|
||||
&nix-error nix-error?
|
||||
&nix-protocol-error nix-protocol-error?
|
||||
nix-protocol-error-message
|
||||
nix-protocol-error-status
|
||||
|
||||
open-connection
|
||||
set-build-options
|
||||
add-text-to-store
|
||||
|
@ -218,6 +225,14 @@ (define-record-type <nix-server>
|
|||
(major nix-server-major-version)
|
||||
(minor nix-server-minor-version))
|
||||
|
||||
(define-condition-type &nix-error &error
|
||||
nix-error?)
|
||||
|
||||
(define-condition-type &nix-protocol-error &nix-error
|
||||
nix-protocol-error?
|
||||
(message nix-protocol-error-message)
|
||||
(status nix-protocol-error-status))
|
||||
|
||||
(define* (open-connection #:optional (file %default-socket-path))
|
||||
(let ((s (with-fluids ((%default-port-encoding #f))
|
||||
;; This trick allows use of the `scm_c_read' optimization.
|
||||
|
@ -265,13 +280,15 @@ (define %stderr-error #x63787470)
|
|||
(status (if (>= (nix-server-minor-version server) 8)
|
||||
(read-int p)
|
||||
1)))
|
||||
(format (current-error-port) "error: ~a (status: ~a)~%"
|
||||
error status)
|
||||
error))
|
||||
(raise (condition (&nix-protocol-error
|
||||
(message error)
|
||||
(status status))))))
|
||||
((= k %stderr-last)
|
||||
#t)
|
||||
(else
|
||||
(error "invalid standard error code" k)))))
|
||||
(raise (condition (&nix-protocol-error
|
||||
(message "invalid error code")
|
||||
(status k))))))))
|
||||
|
||||
(define* (set-build-options server
|
||||
#:key keep-failed? keep-going? try-fallback?
|
||||
|
|
Loading…
Reference in a new issue