aboutsummaryrefslogtreecommitdiff
path: root/gnu/gnunet/mq
diff options
context:
space:
mode:
authorMaxime Devos <maximedevos@telenet.be>2021-09-12 15:38:51 +0200
committerMaxime Devos <maximedevos@telenet.be>2021-09-21 12:21:05 +0200
commit8a9a632f0caf9e0e822dc2cea2619f2802fbd2cd (patch)
treee816786e83c5bf909b3d2b1d9dc20849ba0de1d2 /gnu/gnunet/mq
parent3bd54b0b4f28210d04f9918de2ab16252a929965 (diff)
downloadgnunet-scheme-8a9a632f0caf9e0e822dc2cea2619f2802fbd2cd.tar.gz
gnunet-scheme-8a9a632f0caf9e0e822dc2cea2619f2802fbd2cd.zip
mq/error-reporting: Support error reporting.
Some changes to nse/client will be necessary. * Makefile.am (modules): Add new module. (SCM_TESTS): Add new test. * doc/scheme-gnunet.tm (Error handler): Suggest reporting errors. (Error reporting): New section. * gnu/gnunet/mq/error-reporting.scm: New module. * tests/error-reporting.scm: New tests.
Diffstat (limited to 'gnu/gnunet/mq')
-rw-r--r--gnu/gnunet/mq/error-reporting.scm108
1 files changed, 108 insertions, 0 deletions
diff --git a/gnu/gnunet/mq/error-reporting.scm b/gnu/gnunet/mq/error-reporting.scm
new file mode 100644
index 0000000..41f4f73
--- /dev/null
+++ b/gnu/gnunet/mq/error-reporting.scm
@@ -0,0 +1,108 @@
1;; This file is part of scheme-GNUnet, a partial Scheme port of GNUnet.
2;; Copyright (C) 2021 Maxime Devos <maximedevos@telenet.be>
3;;
4;; scheme-GNUnet is free software: you can redistribute it and/or modify it
5;; under the terms of the GNU Affero General Public License as published
6;; by the Free Software Foundation, either version 3 of the License,
7;; or (at your option) any later version.
8;;
9;; scheme-GNUnet is distributed in the hope that it will be useful, but
10;; WITHOUT ANY WARRANTY; without even the implied warranty of
11;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12;; Affero General Public License for more details.
13;;
14;; You should have received a copy of the GNU Affero General Public License
15;; along with this program. If not, see <http://www.gnu.org/licenses/>.
16;;
17;; SPDX-License-Identifier: AGPL3.0-or-later
18
19;; Summary: Reporting errors from message queues.
20;;
21;; By default, errors are reported to the @code{(current-error-port)},
22;; but this is customisable by parameterising
23;; @code{textual-error-reporting-port}.
24;;
25;; For non-textual error reporting, @code{error-reporter} can be parameterised.
26;; This library is only for _reporting_ errors. What happens after reporting,
27;; is up to the caller.
28(define-library (gnu gnunet mq error-reporting)
29 (export format-error-textually
30 report-error-textually
31 textual-error-reporting-port
32 error-reporter
33 report-error)
34 (import (only (guile)
35 format gettext ngettext current-error-port)
36 (only (srfi srfi-39)
37 make-parameter)
38 (only (rnrs base)
39 begin define case else apply car if lambda cons))
40 (begin
41 ;; TODO: set up translations
42 (define (G_ message)
43 (gettext message "scheme-gnunet"))
44
45 (define (format-message-type type) ; XXX
46 type)
47
48 (define (format-error-textually key . arguments)
49 "Return a textual representation of the error @code{key . arguments},
50translated for the current locale when possible."
51 (case key
52 ((connection:connected)
53 (G_ "the connection to the server has been established"))
54 ((connection:interrupted)
55 (G_ "the connection has been closed before it could be established"))
56 ((input:regular-end-of-file)
57 (G_ "the connection has been broken"))
58 ((input:premature-end-of-file)
59 (G_ "the connection has been broken while there was still some data to read"))
60 ((input:overly-small)
61 (apply (lambda (type size)
62 (if type
63 (format
64 #f
65 (G_ "a message of type ~a and size ~a was smaller than the minimal message size")
66 (format-message-type type)
67 size)
68 (format
69 #f
70 (G_ "a message of size ~a was smaller than the minimal message size")
71 size)))
72 arguments))
73 ((logic:no-handler)
74 (format
75 #f
76 (G_ "no message handler for ~a was found, but a message of that type was received")
77 (format-message-type (car arguments))))
78 ((logic:ill-formed)
79 (format
80 #f
81 (G_ "an ill-formed message of type ~a was received")
82 (format-message-type (car arguments))))
83 (else
84 (format
85 #f
86 (G_ "an unknown error ā€˜~sā€™ was encountered")
87 (cons key arguments)))))
88
89 (define (report-error-textually port key . arguments)
90 "Write a textual representation of the error @code{key . arguments} to
91the output port @var{port}, translated for the current locale if possible."
92 (format port "Scheme-GNUnet: ~a~%"
93 (apply format-error-textually key arguments)))
94
95 (define textual-error-reporting-port
96 (make-parameter #f))
97
98 (define error-reporter
99 (make-parameter
100 (lambda (key . arguments)
101 (define t (textual-error-reporting-port))
102 (if t
103 (apply report-error-textually t key arguments)
104 (apply report-error-textually (current-error-port) key arguments)))))
105
106 (define (report-error key . arguments)
107 "Report the error @code{key . arguments}."
108 (apply (error-reporter) key arguments))))