unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
From: Maxim Cournoyer <maxim.cournoyer@gmail.com>
To: "Ludovic Courtès" <ludo@gnu.org>
Cc: 56075@debbugs.gnu.org
Subject: [bug#56075] [PATCH 1/2] services: configuration: Report the location of field type errors.
Date: Thu, 23 Jun 2022 12:05:16 -0400	[thread overview]
Message-ID: <87y1xn2wn7.fsf@gmail.com> (raw)
In-Reply-To: <20220618213832.25165-1-ludo@gnu.org> ("Ludovic Courtès"'s message of "Sat, 18 Jun 2022 23:38:31 +0200")

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




  parent reply	other threads:[~2022-06-23 16:16 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-18 21:36 [bug#56075] [PATCH 0/2] Report location of invalid configuration field values Ludovic Courtès
2022-06-18 21:38 ` [bug#56075] [PATCH 1/2] services: configuration: Report the location of field type errors Ludovic Courtès
2022-06-18 21:38   ` [bug#56075] [PATCH 2/2] services: configuration: Remove 'validate-configuration' Ludovic Courtès
2022-06-23 18:30     ` Maxim Cournoyer
2022-06-23 16:05   ` Maxim Cournoyer [this message]
2022-06-24 21:43     ` bug#56075: [PATCH 0/2] Report location of invalid configuration field values Ludovic Courtès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87y1xn2wn7.fsf@gmail.com \
    --to=maxim.cournoyer@gmail.com \
    --cc=56075@debbugs.gnu.org \
    --cc=ludo@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).