Commit c0062f50 authored by ROUBY Pierre-Antoine's avatar ROUBY Pierre-Antoine
Browse files

guix-kernel: Add error message when profile creation failed.

* guix-jupyter-kernel.scm (error->shtml, error->html): New procedures.
  (reply-execute-request): Catch 'guix-kernel' exception.
* guix-kernel/environ.scm (make-profile): Catch all exception and throw
  'guix-kernel' exception.
parent bb386a21
......@@ -23,6 +23,7 @@
(ice-9 vlist)
(ice-9 futures)
(ice-9 match)
(sxml simple)
(gnu build linux-container)
(gnu system file-systems)
(guix build syscalls)
......@@ -197,6 +198,24 @@
(+ count 1))))
;;
;; Html.
;;
(define (error->shtml error)
(match error
(('guix-kernel msg errno)
`(h3 (@ (style "color: red;"))
,(string-append "Error: " msg)))
(_
`(h3 (@ (style "color: red;"))
"Error !"))))
(define (error->html error)
(call-with-output-string
(lambda (port)
(sxml->xml (error->shtml error) port))))
;;
;; Handlers.
;;
......@@ -251,40 +270,49 @@
count)
(let* ((code (hash-ref (json-string->scm content) "code"))
(magic (get-magic-line code)))
(cond
((magic-env? code)
(let* ((list (string-split magic #\ ))
(env-name (list-ref list 2))
(env (list-cdr-ref list 4)))
(if (container-by-name containers env-name)
(catch 'guix-kernel
(λ ()
(cond
((magic-env? code)
(let* ((list (string-split magic #\ ))
(env-name (list-ref list 2))
(env (list-cdr-ref list 4)))
(if (container-by-name containers env-name)
(values containers
(proxy-exec-container containers env-name
parts count))
(let* ((id (run-new-container env-name env))
(container (new-container-connect env-name id))
(new (register-container containers env-name
container)))
(values new
(proxy-exec-container new env-name
parts count))))))
((or (magic-run? code)
(magic-kernel? code))
(let* ((list (string-split magic #\ ))
(env-name (list-ref list 2)))
(values containers
(proxy-exec-container containers env-name
parts count))
(let* ((id (run-new-container env-name env))
(container (new-container-connect env-name id))
(new (register-container containers env-name
container)))
(values new
(proxy-exec-container new env-name
parts count))))))
((or (magic-run? code)
(magic-kernel? code))
(let* ((list (string-split magic #\ ))
(env-name (list-ref list 2)))
parts count))))
((magic-html? code)
(values containers
(reply-html socket socket-iopub
uuid header- parent-header
metadata content
(delete-magic code)
notebook-info-key count)))
(else
(values containers
(proxy-exec-container containers "default"
parts count)))))
(λ error
(values containers
(proxy-exec-container containers env-name
parts count))))
((magic-html? code)
(values containers
(reply-html socket socket-iopub
uuid header- parent-header
metadata content
(delete-magic code)
notebook-info-key count)))
(else
(values containers
(proxy-exec-container containers "default"
parts count))))))
(reply-html socket socket-iopub
uuid header- parent-header
metadata content
(error->html error)
notebook-info-key count))))))
(define (shutdown socket uuid header- parent-header
metadata content parts containers
......
......@@ -105,7 +105,11 @@
(define (make-profile packages)
"Create profile with all PACKAGES, and return profile path."
(new-profile->path packages))
(catch #t
(λ ()
(new-profile->path packages))
(λ error
(throw 'guix-kernel "Package not found !" error))))
(define (env->str name value)
(string-append (string-upcase name) "="
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment