[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnunet-scheme] 269/324: mq/error-reporting: Support error reporting.
From: |
gnunet |
Subject: |
[gnunet-scheme] 269/324: mq/error-reporting: Support error reporting. |
Date: |
Tue, 21 Sep 2021 13:25:09 +0200 |
This is an automated email from the git hooks/post-receive script.
maxime-devos pushed a commit to branch master
in repository gnunet-scheme.
commit 8a9a632f0caf9e0e822dc2cea2619f2802fbd2cd
Author: Maxime Devos <maximedevos@telenet.be>
AuthorDate: Sun Sep 12 15:38:51 2021 +0200
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.
---
Makefile.am | 2 +
doc/scheme-gnunet.tm | 21 +++++++-
gnu/gnunet/mq/error-reporting.scm | 108 ++++++++++++++++++++++++++++++++++++++
tests/error-reporting.scm | 63 ++++++++++++++++++++++
4 files changed, 193 insertions(+), 1 deletion(-)
diff --git a/Makefile.am b/Makefile.am
index 8d8fca7..5735a75 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -41,6 +41,7 @@ modules = \
gnu/gnunet/concurrency/repeated-condition.scm \
\
gnu/gnunet/mq/envelope.scm \
+ gnu/gnunet/mq/error-reporting.scm \
gnu/gnunet/mq/handler.scm \
gnu/gnunet/mq/prio-prefs.scm \
gnu/gnunet/mq/prio-prefs2.scm \
@@ -147,6 +148,7 @@ SCM_LOG_DRIVER = \
SCM_TESTS = \
tests/envelope.scm \
+ tests/error-reporting.scm \
tests/message-handler.scm \
tests/mq.scm \
tests/mq-stream.scm \
diff --git a/doc/scheme-gnunet.tm b/doc/scheme-gnunet.tm
index 49b5a74..01234b1 100644
--- a/doc/scheme-gnunet.tm
+++ b/doc/scheme-gnunet.tm
@@ -481,7 +481,9 @@
Consider automatically reconnecting after
<scm|<scm|input:regular-end-of-file>> and
<scm|<scm|input:premature-end-of-file>>, to allow the server to restart
- without having to manually restart every individual application.
+ without having to manually restart every individual
+ application.<space|1em>To report errors, see the section
+ <reference|sec:error reporting> Error reporting.
<subsection|Ordering of injected errors and messages and sent messages>
@@ -546,6 +548,23 @@
be formed, <scm|connection:interrupted> is injected instead of
<scm|connection:connected> and <scm|connection:regular-end-of-file>.
+ <section|Error reporting><label|sec:error reporting>
+
+ <index|error reporting>Errors can be reported with the procedure
+ <scm|report-error> from the module <scm|(gnu gnunet mq
+ error-reporting)>.<space|1em>It can be called as <scm|(report-error key
+ argument ...)>, e.g. <scm|(report-error 'logic:no-handler 3)>.<space|1em>By
+ default, it reports the error to the current error port.<space|1em>If this
+ is not desired, the output can be sent to another port by setting the
+ parameter <scm|textual-error-reporting-port>.<space|1em>If textual error
+ reporting is not desired, the parameter <scm|error-reporter> can be set to
+ a procedure with the same interface as <scm|report-error>.<space|1em>Such a
+ procedure could e.g. open a GUI dialog, sent the message to the system
+ logger or ignore the error.
+
+ Error messages are translated for the current locale.<todo|TODO actually
+ call bindtextdomain>
+
<section|Estimation of the size of the network>
<index|network size estimation>GNUnet has a service that roughly estimates
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 @@
+;; This file is part of scheme-GNUnet, a partial Scheme port of GNUnet.
+;; Copyright (C) 2021 Maxime Devos <maximedevos@telenet.be>
+;;
+;; scheme-GNUnet is free software: you can redistribute it and/or modify it
+;; under the terms of the GNU Affero General Public License as published
+;; by the Free Software Foundation, either version 3 of the License,
+;; or (at your option) any later version.
+;;
+;; scheme-GNUnet is distributed in the hope that it will be useful, but
+;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+;; Affero General Public License for more details.
+;;
+;; You should have received a copy of the GNU Affero General Public License
+;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+;;
+;; SPDX-License-Identifier: AGPL3.0-or-later
+
+;; Summary: Reporting errors from message queues.
+;;
+;; By default, errors are reported to the @code{(current-error-port)},
+;; but this is customisable by parameterising
+;; @code{textual-error-reporting-port}.
+;;
+;; For non-textual error reporting, @code{error-reporter} can be parameterised.
+;; This library is only for _reporting_ errors. What happens after reporting,
+;; is up to the caller.
+(define-library (gnu gnunet mq error-reporting)
+ (export format-error-textually
+ report-error-textually
+ textual-error-reporting-port
+ error-reporter
+ report-error)
+ (import (only (guile)
+ format gettext ngettext current-error-port)
+ (only (srfi srfi-39)
+ make-parameter)
+ (only (rnrs base)
+ begin define case else apply car if lambda cons))
+ (begin
+ ;; TODO: set up translations
+ (define (G_ message)
+ (gettext message "scheme-gnunet"))
+
+ (define (format-message-type type) ; XXX
+ type)
+
+ (define (format-error-textually key . arguments)
+ "Return a textual representation of the error @code{key . arguments},
+translated for the current locale when possible."
+ (case key
+ ((connection:connected)
+ (G_ "the connection to the server has been established"))
+ ((connection:interrupted)
+ (G_ "the connection has been closed before it could be established"))
+ ((input:regular-end-of-file)
+ (G_ "the connection has been broken"))
+ ((input:premature-end-of-file)
+ (G_ "the connection has been broken while there was still some data to
read"))
+ ((input:overly-small)
+ (apply (lambda (type size)
+ (if type
+ (format
+ #f
+ (G_ "a message of type ~a and size ~a was smaller than
the minimal message size")
+ (format-message-type type)
+ size)
+ (format
+ #f
+ (G_ "a message of size ~a was smaller than the minimal
message size")
+ size)))
+ arguments))
+ ((logic:no-handler)
+ (format
+ #f
+ (G_ "no message handler for ~a was found, but a message of that type
was received")
+ (format-message-type (car arguments))))
+ ((logic:ill-formed)
+ (format
+ #f
+ (G_ "an ill-formed message of type ~a was received")
+ (format-message-type (car arguments))))
+ (else
+ (format
+ #f
+ (G_ "an unknown error ‘~s’ was encountered")
+ (cons key arguments)))))
+
+ (define (report-error-textually port key . arguments)
+ "Write a textual representation of the error @code{key . arguments} to
+the output port @var{port}, translated for the current locale if possible."
+ (format port "Scheme-GNUnet: ~a~%"
+ (apply format-error-textually key arguments)))
+
+ (define textual-error-reporting-port
+ (make-parameter #f))
+
+ (define error-reporter
+ (make-parameter
+ (lambda (key . arguments)
+ (define t (textual-error-reporting-port))
+ (if t
+ (apply report-error-textually t key arguments)
+ (apply report-error-textually (current-error-port) key
arguments)))))
+
+ (define (report-error key . arguments)
+ "Report the error @code{key . arguments}."
+ (apply (error-reporter) key arguments))))
diff --git a/tests/error-reporting.scm b/tests/error-reporting.scm
new file mode 100644
index 0000000..dfd72c3
--- /dev/null
+++ b/tests/error-reporting.scm
@@ -0,0 +1,63 @@
+;; This file is part of scheme-GNUnet, a partial Scheme port of GNUnet.
+;; Copyright (C) 2021 Maxime Devos <maximedevos@telenet.be>
+;;
+;; scheme-GNUnet is free software: you can redistribute it and/or modify it
+;; under the terms of the GNU Affero General Public License as published
+;; by the Free Software Foundation, either version 3 of the License,
+;; or (at your option) any later version.
+;;
+;; scheme-GNUnet is distributed in the hope that it will be useful, but
+;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+;; Affero General Public License for more details.
+;;
+;; You should have received a copy of the GNU Affero General Public License
+;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+;;
+;; SPDX-License-Identifier: AGPL-3.0-or-later
+(import (gnu gnunet mq error-reporting)
+ (srfi srfi-43)
+ (only (rnrs base) assert))
+
+(test-begin "error-reporting")
+
+(define %errors
+ '((connection:connected)
+ (connection:interrupted)
+ (input:regular-end-of-file)
+ (input:premature-end-of-file)
+ (input:overly-small 1 3)
+ (input:overly-small #f 3)
+ (logic:no-handler 5)
+ (logic:ill-formed 6)
+ (some unexpected error !)))
+
+(test-assert "report-error doesn't fail"
+ (begin
+ (for-each (lambda (x)
+ (apply report-error x))
+ %errors)
+ #t))
+
+(test-assert "report-error-textually ends with a newline"
+ (for-each
+ (lambda (x)
+ (pk 'x x)
+ (assert (string-suffix? "\n"
+ (call-with-output-string
+ (lambda (port)
+ (apply report-error-textually port x)))))
+ #t)
+ %errors))
+
+(test-equal "report-error output can be redirected"
+ (call-with-output-string
+ (lambda (port)
+ (parameterize ((textual-error-reporting-port port))
+ (apply report-error '(logic:no-handler 1)))))
+ (call-with-output-string
+ (lambda (port)
+ (parameterize ((current-error-port port))
+ (apply report-error '(logic:no-handler 1))))))
+
+(test-end "error-reporting")
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [gnunet-scheme] 255/324: nse/client: Remove resolved TODO., (continued)
- [gnunet-scheme] 255/324: nse/client: Remove resolved TODO., gnunet, 2021/09/21
- [gnunet-scheme] 264/324: build: Use $< and $@ for PDF and HTML generation., gnunet, 2021/09/21
- [gnunet-scheme] 252/324: nse/client: Allow disconnecting., gnunet, 2021/09/21
- [gnunet-scheme] 263/324: build: Introduce TEXMACS_CONVERT variable., gnunet, 2021/09/21
- [gnunet-scheme] 267/324: build: Distribute and install TeXmacs documentation., gnunet, 2021/09/21
- [gnunet-scheme] 260/324: git: Ignore generated documentation., gnunet, 2021/09/21
- [gnunet-scheme] 262/324: build: Delete .go when running "make clean"., gnunet, 2021/09/21
- [gnunet-scheme] 265/324: build: Find .scmfrag files when building out-of-tree., gnunet, 2021/09/21
- [gnunet-scheme] 268/324: build: Distribute the tests., gnunet, 2021/09/21
- [gnunet-scheme] 270/324: nse/client: Report errors and reconnect., gnunet, 2021/09/21
- [gnunet-scheme] 269/324: mq/error-reporting: Support error reporting.,
gnunet <=
- [gnunet-scheme] 273/324: nse/client: Use 'spawn' instead of hardcoding 'spawn-fiber'., gnunet, 2021/09/21
- [gnunet-scheme] 275/324: nse/client: Remove default for 'spawn'., gnunet, 2021/09/21
- [gnunet-scheme] 277/324: tests/network-size: Make ‘reconnects’ test reproducible., gnunet, 2021/09/21
- [gnunet-scheme] 271/324: tests: Abstract setting of O_NONBLOCK., gnunet, 2021/09/21
- [gnunet-scheme] 272/324: tests/network-size: Abstract configuration creation., gnunet, 2021/09/21
- [gnunet-scheme] 274/324: nse/client: Remove rest arguments., gnunet, 2021/09/21
- [gnunet-scheme] 276/324: nse/client: Stop reconnecting when a disconnect is requested., gnunet, 2021/09/21
- [gnunet-scheme] 278/324: doc: Use MathML instead of PNG images., gnunet, 2021/09/21
- [gnunet-scheme] 279/324: build: Remove resolved TODO., gnunet, 2021/09/21
- [gnunet-scheme] 280/324: config/fs: Locate the user and system configuration., gnunet, 2021/09/21