aboutsummaryrefslogtreecommitdiff
path: root/haunt/jakob/dynamic/captcha.scm
diff options
context:
space:
mode:
authorJakob L. Kreuze2022-11-23 19:16:45 -0500
committerJakob L. Kreuze2022-11-23 19:23:26 -0500
commit4f1743dad652d9a3781b268294b89d22c57528c0 (patch)
treed15ead9c06b7140f383bcc09c0058963933aea6d /haunt/jakob/dynamic/captcha.scm
parent2a7b250df5fa9611c2270c5837fab9fab750563c (diff)
[dynamic] Refactor and improve error reporting with R6RS exceptions
Diffstat (limited to 'haunt/jakob/dynamic/captcha.scm')
-rw-r--r--haunt/jakob/dynamic/captcha.scm11
1 files changed, 6 insertions, 5 deletions
diff --git a/haunt/jakob/dynamic/captcha.scm b/haunt/jakob/dynamic/captcha.scm
index 05426d1..b71bb23 100644
--- a/haunt/jakob/dynamic/captcha.scm
+++ b/haunt/jakob/dynamic/captcha.scm
@@ -26,9 +26,11 @@
#:use-module (ice-9 match)
#:use-module (ice-9 popen)
#:use-module (ice-9 threads)
+ #:use-module (jakob dynamic errors)
#:use-module (json)
#:use-module (rnrs bytevectors)
#:use-module ((rnrs base) #:select (assert))
+ #:use-module (rnrs conditions)
#:use-module (rnrs exceptions)
#:use-module (srfi-197)
#:use-module (srfi srfi-1)
@@ -168,7 +170,7 @@ internally-defined `time-to-live-seconds'."
('x 1)
(n (if (number? n)
0
- (error "Do not know how to differentiate.")))))
+ (error "Do not know how to differentiate." n)))))
(define (simplify-sexp sexp)
(match sexp
@@ -202,11 +204,11 @@ internally-defined `time-to-live-seconds'."
\\end{document}
" src)))
(unless (eqv? 0 (status:exit-val (system "pdflatex formula.tex")))
- (error "Cannot generate PDF"))
+ (error "Cannot generate PDF" #f))
(let* ((port (open-input-pipe "convert -density 300 formula.pdf -quality 90 png:-"))
(data (get-bytevector-all port)))
(unless (eqv? 0 (status:exit-val (close-pipe port)))
- (error "Cannot generate PNG"))
+ (error "Cannot generate PNG" #f))
data)))
(define (new-captcha!)
@@ -266,8 +268,7 @@ internally-defined `time-to-live-seconds'."
(define (validate-proof-of-work! prefix challenge-id)
(define zero-prefix (string-join (map (lambda (_) "0") (iota %hardness)) ""))
(when (member challenge-id (id-queue-free pow-challenge-id-queue))
- (raise (condition (&message
- (message "No such challenge ID")))))
+ (panic "No such challenge ID"))
(let* ((challenge (hash-ref pow-challenges challenge-id))
(hash-value (chain (list prefix challenge)
(string-concatenate _)

© 2015 - 2026 Jakob L. Kreuze