From 9562a2eb6162ea6712fe31529c30002a83313dd8 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Thu, 29 Apr 2021 00:38:03 +0200 Subject: diagnostics, ui: Adjust to 'read-error' and 'syntax-error' in Guile 3.0.6. * guix/diagnostics.scm (source-properties->location): Add clause for vectors. * guix/ui.scm (report-load-error): Tweak 'read-error' handling for 3.0.6. * tests/guix-package.sh: Relax regexp for the "unbound variable" diagnostic check. * tests/guix-system.sh: Adjust "missing closing paren" check for 3.0.6. * tests/records.scm (location-alist): New procedure. ("define-record-type* & wrong field specifier") ("define-record-type* & wrong field specifier, identifier") ("define-record-type* & duplicate initializers"): Use it. --- guix/diagnostics.scm | 6 +++++- guix/ui.scm | 10 ++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) (limited to 'guix') diff --git a/guix/diagnostics.scm b/guix/diagnostics.scm index 7b9ffc61b5..6a792febd4 100644 --- a/guix/diagnostics.scm +++ b/guix/diagnostics.scm @@ -1,5 +1,5 @@ ;;; GNU Guix --- Functional package management for GNU -;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Ludovic Courtès +;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021 Ludovic Courtès ;;; ;;; This file is part of GNU Guix. ;;; @@ -233,6 +233,10 @@ etc." (make-location file (+ line 1) col))) (#f #f) + (#(file line column) + ;; Guile >= 3.0.6 uses vectors instead of alists internally, which can be + ;; seen in the arguments to 'syntax-error' exceptions. + (location file (+ 1 line) column)) (_ (let ((file (assq-ref loc 'filename)) (line (assq-ref loc 'line)) diff --git a/guix/ui.scm b/guix/ui.scm index 7fbd4c63a2..334dce2c68 100644 --- a/guix/ui.scm +++ b/guix/ui.scm @@ -376,12 +376,14 @@ ARGS is the list of arguments received by the 'throw' handler." (('system-error . rest) (let ((err (system-error-errno args))) (report-error (G_ "failed to load '~a': ~a~%") file (strerror err)))) - (('read-error "scm_i_lreadparen" message _ ...) + (('read-error _ message args ...) ;; Guile's missing-paren messages are obscure so we make them more ;; intelligible here. - (if (string-suffix? "end of file" message) - (let ((location (string-drop-right message - (string-length "end of file")))) + (if (or (string-suffix? "end of file" message) ;Guile < 3.0.6 + (and (string-contains message "unexpected end of input") + (member '(#\)) args))) + (let ((location (string-take message + (+ 2 (string-contains message ": "))))) (format (current-error-port) (G_ "~amissing closing parenthesis~%") location)) (apply throw args))) -- cgit v1.2.3