Mkgmap always returns exit code 0 even when it fails

Hi, I'm building a map generation tool with Ant. Problem is that if mkgmap encounters an error, the exit code is 0, no matter what. As this is the "OK" exit code, Ant carries on to the rest of the workflow. On the contrary, splitter does return a non zero code when it fails. Please make mkgmap return a non zero exit code for errors. Thanks, Paco

Hi Paco, I agree, but I found no simple way to change mkgmap. I assume that you consider a non empty stderr file as an error, so maybe we can check whether anything was written to stderr, but sometimes we use this file also for important hints like this: "WARNING: input files have different code pages" BTW: Also splitter doesn't make sure that it ends with a non-zero return code in case of errors, but it tries to do so. Gerd
Date: Sat, 11 Jan 2014 00:22:54 +0100 From: paco.tyson@free.fr To: mkgmap-dev@lists.mkgmap.org.uk Subject: [mkgmap-dev] Mkgmap always returns exit code 0 even when it fails
Hi,
I'm building a map generation tool with Ant. Problem is that if mkgmap encounters an error, the exit code is 0, no matter what. As this is the "OK" exit code, Ant carries on to the rest of the workflow. On the contrary, splitter does return a non zero code when it fails.
Please make mkgmap return a non zero exit code for errors.
Thanks, Paco _______________________________________________ mkgmap-dev mailing list mkgmap-dev@lists.mkgmap.org.uk http://www.mkgmap.org.uk/mailman/listinfo/mkgmap-dev

Selon Gerd Petermann <gpetermann_muenchen@hotmail.com>:
Hi Paco,
I agree, but I found no simple way to change mkgmap. I assume that you consider a non empty stderr file as an error,
No, Ant checks for the return code : I invoke the java task with the failonerror attribute (http://ant.apache.org/manual/Tasks/java.html#failonerror) which explicitly mentions the result code. The result code is set in the Java code with the System.exit() method.
so maybe we can check whether anything was written to stderr, but sometimes we use this file also for important hints like this: "WARNING: input files have different code pages"
I agree with you, mkgmap outputs lots of warnings, this workaround would be tricky at best. It would work if we output information and warnings to stdout and errors and exceptions to stderr but that requires a check on the complete codebase. I ran a grep for System.exit on the codebase and found several calls to System.exit(), adding a few of them in the right places (e.g. at the end of the options processing, catching any exception mkgmap can't deal with...) should do the trick. Forgive me if I'm wrong here, it's been 10 years since I wrote a single line of java code.
BTW: Also splitter doesn't make sure that it ends with a non-zero return code in case of errors, but it tries to do so.
As far as I remember, I've run into incorrect options or missing file errors, splitter always behaved as expected.
Gerd
Date: Sat, 11 Jan 2014 00:22:54 +0100 From: paco.tyson@free.fr To: mkgmap-dev@lists.mkgmap.org.uk Subject: [mkgmap-dev] Mkgmap always returns exit code 0 even when it fails
Hi,
I'm building a map generation tool with Ant. Problem is that if mkgmap encounters an error, the exit code is 0, no matter what. As this is the "OK" exit code, Ant carries on to the rest of the workflow. On the contrary, splitter does return a non zero code when it fails.
Please make mkgmap return a non zero exit code for errors.
Thanks, Paco _______________________________________________ mkgmap-dev mailing list mkgmap-dev@lists.mkgmap.org.uk http://www.mkgmap.org.uk/mailman/listinfo/mkgmap-dev

Hi Paco,
No, Ant checks for the return code : I invoke the java task with the failonerror attribute (http://ant.apache.org/manual/Tasks/java.html#failonerror) which explicitly mentions the result code. The result code is set in the Java code with the System.exit() method. yes, that's what ant does. My question was how you decide that mkgmap failed.
so maybe we can check whether anything was written to stderr, but sometimes we use this file also for important hints like this: "WARNING: input files have different code pages"
I agree with you, mkgmap outputs lots of warnings, this workaround would be tricky at best. It would work if we output information and warnings to stdout and errors and exceptions to stderr but that requires a check on the complete codebase.
I ran a grep for System.exit on the codebase and found several calls to System.exit(), adding a few of them in the right places (e.g. at the end of the options processing, catching any exception mkgmap can't deal with...) should do the trick. Forgive me if I'm wrong here, it's been 10 years since I wrote a single line of java code.
your welcome. In fact only very few of the System.exit() calls are reachable if your execute mkgmap main. They are used in stand-alone programs. Anyhow, I think we should at least manage to stop with non zero return code when parameter checks fail or input files are missing or if one output file was not not completely written. It is much more difficult to keep track of error messages regarding the quality of the output.
BTW: Also splitter doesn't make sure that it ends with a non-zero return code in case of errors, but it tries to do so.
As far as I remember, I've run into incorrect options or missing file errors, splitter always behaved as expected. yes, those typical user errors are probably all catched. One example that is not: if the input is an invalid o5m file you might see a traceback but splitter ends with rc 0.
Gerd
participants (3)
-
Andrzej Popowski
-
Gerd Petermann
-
paco.tyson@free.fr