guix-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug#56075] [PATCH 1/2] services: configuration: Report the location of


From: Maxim Cournoyer
Subject: [bug#56075] [PATCH 1/2] services: configuration: Report the location of field type errors.
Date: Thu, 23 Jun 2022 12:05:16 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.1 (gnu/linux)

Hello,

Ludovic Courtès <ludo@gnu.org> writes:

> Previously field type errors would be reported in a non-standard way,
> and without any source location information.  This fixes it.
>
> * gnu/services/configuration.scm (configuration-field-error): Add a
> 'loc' parameter and honor it.  Use 'formatted-message' instead of plain
> 'format'.
> (define-configuration-helper)[field-sanitizer]: New procedure.
> Use it.  Use STEM as the identifier of the syntactic constructor of the
> record type.  Add a 'sanitize' property to each field.  Remove now
> useless STEM macro that would call 'validate-configuration'.
> * gnu/services/mail.scm (serialize-listener-configuration): Adjust to
> new 'configuration-field-error' prototype.
> * tests/services/configuration.scm ("wrong type for a field"): New test.
> * po/guix/POTFILES.in: Add gnu/services/configuration.scm.

Very nice!  I had been meaning to look at what define-configure could be
improved w.r.t. the recently added sanitizers; I felt perhaps
`define-configure' would perhaps loose its relevance, but I'm happy to
see you saw value in upgrading it!

The first part LGTM, although I so rarely dabble with syntax-case that
it looks a bit alien to my eyes now.

[...]

> --- a/tests/services/configuration.scm
> +++ b/tests/services/configuration.scm
> @@ -19,6 +19,7 @@

You forgot to add your copyright notice line.

>  (define-module (tests services configuration)
>    #:use-module (gnu services configuration)
> +  #:use-module (guix diagnostics)
>    #:use-module (guix gexp)
>    #:use-module (srfi srfi-34)
>    #:use-module (srfi srfi-64))
> @@ -43,6 +44,17 @@ (define-configuration port-configuration
>    80
>    (port-configuration-port (port-configuration)))
>
> +(test-equal "wrong type for a field"
> +  '("configuration.scm" 56 11)                    ;error location
> +  (guard (c ((configuration-error? c)
> +             (let ((loc (error-location c)))
> +               (list (basename (location-file loc))
> +                     (location-line loc)
> +                     (location-column loc)))))
> +    (port-configuration
> +     ;; This is line 55; the test relies on line/column numbers!
> +     (port "This is not a number!"))))
> +

It seems fragile to rely on the line/column number, but if we truly need
to test that, I don't see a better options.

Thanks,

Maxim





reply via email to

[Prev in Thread] Current Thread [Next in Thread]