texinfo-commits
[Top][All Lists]
Advanced

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

branch master updated: Fatal error for init file loading


From: Gavin D. Smith
Subject: branch master updated: Fatal error for init file loading
Date: Sat, 02 Sep 2023 19:26:58 -0400

This is an automated email from the git hooks/post-receive script.

gavin pushed a commit to branch master
in repository texinfo.

The following commit(s) were added to refs/heads/master by this push:
     new 90fdceb50c Fatal error for init file loading
90fdceb50c is described below

commit 90fdceb50c9a610f0e5c8ce003a6bec5898467db
Author: Gavin Smith <gavinsmith0123@gmail.com>
AuthorDate: Sun Sep 3 00:26:28 2023 +0100

    Fatal error for init file loading
    
    * tp/Texinfo/Config.pm (_GNUT_document_fatal): copy
    from _GNUT_document_warn and exit program.
    (_GNUT_load_init_file): Load init file with "do" rather than
    "require".  As calling code has already located the file with
    Texinfo::Common::locate_init_file, we do not need "require" to
    locate the file in @INC.  Call _GNUT_document_fatal if "do"
    could not load or parse the file.
    
    Report from Jonas Hahnfeld who is working on an init file for
    GNU Lilypond.  It was not helpful to continue on if there
    was a syntax error in the init file.
---
 ChangeLog            | 16 ++++++++++++++++
 tp/Texinfo/Config.pm | 40 +++++++++++++++++++++++++++++++---------
 2 files changed, 47 insertions(+), 9 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 963e77a9e4..6169811373 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2023-09-02  Gavin Smith <gavinsmith0123@gmail.com>
+
+       Fatal error for init file loading
+
+       * tp/Texinfo/Config.pm (_GNUT_document_fatal): copy
+       from _GNUT_document_warn and exit program.
+       (_GNUT_load_init_file): Load init file with "do" rather than
+       "require".  As calling code has already located the file with
+       Texinfo::Common::locate_init_file, we do not need "require" to
+       locate the file in @INC.  Call _GNUT_document_fatal if "do"
+       could not load or parse the file.
+
+       Report from Jonas Hahnfeld who is working on an init file for
+       GNU Lilypond.  It was not helpful to continue on if there
+       was a syntax error in the init file.
+
 2023-09-01  Patrice Dumas <pertusus@free.fr>
 
        Run 'gnulib-tool --add-import libunistring' under tp/Texinfo/XS.
diff --git a/tp/Texinfo/Config.pm b/tp/Texinfo/Config.pm
index 47082541fa..52f0ca969f 100644
--- a/tp/Texinfo/Config.pm
+++ b/tp/Texinfo/Config.pm
@@ -121,23 +121,45 @@ sub _GNUT_document_warn($) {
                    "%s: warning: %s"), $real_command_name, $text)."\n"));
 }
 
+sub _GNUT_document_fatal($) {
+  my $text = shift;
+  chomp ($text);
+  die(_GNUT_encode_message(
+        sprintf(__p("program name: error_message",
+                   "%s: %s"), $real_command_name, $text)."\n"));
+}
+
 # used to register messages by the user with texinfo_register_init_loading_*
 my @init_file_loading_messages;
+
 # called from texi2any.pl main program and t/test_utils.pl.
 # eval $FILE in the Texinfo::Config namespace. $FILE should be a binary string.
 sub GNUT_load_init_file($) {
   my $file = shift;
   push @init_file_loading_messages, [];
-  eval { require($file) ;};
-  my $e = $@;
-  if ($e ne '') {
-    # $e may not be correctly encoded, but it is not clear what is to
-    # be expected.  In the eval documentation there is only information
-    # on the string eval case, not the block eval used here, and the
-    # information is not particularly clear.
-    _GNUT_document_warn(sprintf(__("error loading %s: %s"),
-                _GNUT_decode_input($file), $e));
+
+  my $result = do($file);
+  my $message = $@;
+  my $read_error = $!;
+
+  if (!defined($result)) {
+    if (defined($message)) {
+      _GNUT_document_fatal(sprintf
+                 (__("error parsing %s: %s"),
+                  _GNUT_decode_input($file), $message));
+    } elsif (defined($read_error)) {
+      _GNUT_document_fatal(sprintf
+                 (__("error reading %s: %s"),
+                  _GNUT_decode_input($file), $read_error));
+    }
   }
+
+  # Note: $message or $read_error may be incorrectly "double encoded" if they
+  # are encoded byte strings.  However, it appears that they are unencoded
+  # character strings if the init file uses the "use utf8" pragma to mark the
+  # file as UTF-8 encoded, which may become the default in the future according
+  # to the Perl documentation.
+
   my $file_loading_messages = pop @init_file_loading_messages;
   my $error_nr = 0;
   for my $error (@{$file_loading_messages}) {



reply via email to

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