[Top][All Lists]

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

[gnuastro-commits] master e7afee6 3/3: Option parsing: warning printed w

From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master e7afee6 3/3: Option parsing: warning printed when --config value doesn't exist
Date: Thu, 29 Apr 2021 19:46:11 -0400 (EDT)

branch: master
commit e7afee6b77bca165dacfebcb1b4db5bfdbeeb98b
Author: Mohammad Akhlaghi <>
Commit: Mohammad Akhlaghi <>

    Option parsing: warning printed when --config value doesn't exist
    Until now, when the user specified a configuration file (with '--config')
    and the file doesn't exist, Gnuastro programs wouldn't crash or print any
    warning, but they would ignore it and continue quietly. This could lead to
    bad confusions when there was a problem in readin the file (e.g., a typo in
    the file name, change of location, no permission, or etc).
    This is the expected behavior for default configuration files (we don't
    want to bother the user about non-existent default directory or user
    configuration files). But it shouldn't be the case for user-given
    configuration files.
    With this commit a warning will now be printed when a file given to the
    '--config' option can't be opened for any reason. But because configuration
    files are generally optional, the program won't abort. Hopefully the
    warning will be clear enough.
    This bug was reported by Sepideh Eskandarlou.
 NEWS              |  1 +
 doc/gnuastro.texi |  4 +++-
 lib/options.c     | 10 ++++++++--
 3 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/NEWS b/NEWS
index 897b1c5..3b56f80 100644
--- a/NEWS
+++ b/NEWS
@@ -244,6 +244,7 @@ See the end of the file for license conditions.
   bug #60082: Arithmetic library crash for integer operators like modulo
   bug #60121: Arithmetic segfault when multi-operand output given to set-
   bug #60368: CosmicCalculator fails --setdirconf when redshift isn't given
+  bug #60483: No warning when file given to '--config' doesn't exist
   bug #60484: Match crashes when called with --coord and --ccol2 (together)
diff --git a/doc/gnuastro.texi b/doc/gnuastro.texi
index 3f710ab..b23fd9a 100644
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ -7361,9 +7361,11 @@ No program will actually start its processing when this 
option is called.
 The otherwise mandatory arguments for each program (for example input image or 
catalog files) are no longer required when you call this option.
 @item --config=STR
-Parse @option{STR} as a configuration file immediately when this option is 
confronted (see @ref{Configuration files}).
+Parse @option{STR} as a configuration file name, immediately when this option 
is confronted (see @ref{Configuration files}).
 The @option{--config} option can be called multiple times in one run of any 
Gnuastro program on the command-line or in the configuration files.
 In any case, it will be immediately read (before parsing the rest of the 
options on the command-line, or lines in a configuration file).
+If the given file doesn't exist or can't be read for any reason, the program 
will print a warning and continue its processing.
+The warning can be suppressed with @option{--quiet}.
 Note that by definition, options on the command-line still take precedence 
over those in any configuration file, including the file(s) given to this 
option if they are called before it.
 Also see @option{--lastconfig} and @option{--onlyversion} on how this option 
can be used for reproducible results.
diff --git a/lib/options.c b/lib/options.c
index 2ee3ab2..dc06359 100644
--- a/lib/options.c
+++ b/lib/options.c
@@ -2184,7 +2184,7 @@ options_lastconfig_has_been_called(struct argp_option 
 static void
 options_parse_file(char *filename,  struct gal_options_common_params *cp,
-                   int enoent_abort)
+                   int warning)
   FILE *fp;
   char *line, *name, *arg;
@@ -2201,7 +2201,13 @@ options_parse_file(char *filename,  struct 
gal_options_common_params *cp,
      ignore the configuration file and return. */
   fp=fopen(filename, "r");
-  if(fp==NULL) return;
+  if(fp==NULL)
+    {
+      /* Print a warning  */
+      if(warning && cp->quiet==0)
+        error(EXIT_SUCCESS, errno, "%s", filename);
+      return;
+    }
   /* If necessary, print the configuration file name. */

reply via email to

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