summaryrefslogtreecommitdiff
path: root/src/scm/webid-oidc/errors.scm
blob: 4a28425971f4d52259147bbd3db7d9102e5a4ef1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
(define-module (webid-oidc errors)
  #:use-module ((webid-oidc stubs) #:prefix stubs:)
  #:use-module (ice-9 exceptions)
  #:use-module (ice-9 optargs)
  #:use-module (ice-9 i18n))

(define (G_ text)
  (let ((out (gettext text)))
    (if (string=? out text)
        ;; No translation, disambiguate
        (car (reverse (string-split text #\|)))
        out)))

;; This is a collection of all errors that can happen, and a function
;; to log them.

(define*-public (error->str error #:key (max-depth #f))
  (if (record? error)
      (let* ((type (record-type-descriptor error))
             (get
              (lambda (slot)
                ((record-accessor type slot) error)))
             (recurse
              (if (eqv? max-depth 0)
                  (lambda (err) (G_ "that’s how it is"))
                  (lambda (err)
                    (error->str err #:max-depth (and max-depth (- max-depth 1)))))))
        (case (record-type-name type)
          (else
           (error (format #f "Unhandled exception type ~a." (record-type-name type))))))
      (format #f "~a" error)))