(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)))