git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[StGit PATCH] Handle commandline parsing errors gracefully

From
Karl Hasselström <kha@treskal.com>
Date
Apr 20, 2008, 13:19 UTC
Message-ID
<20080420131847.8824.87769.stgit@yoghurt>

The commandline option parser raises SystemExit after having explained to the user what she did wrong. A recent refactoring introduced a catch-all "except:" at the top level, which caught the SystemExit and printed a traceback.

Let's just simply exit instead, like we used to.
Signed-off-by: Karl Hasselström <kha@treskal.com>
---
This goes on the "master" branch.
 stgit/main.py |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/stgit/main.py b/stgit/main.py
index 663fdec..aa1f8ef 100644
--- a/stgit/main.py
+++ b/stgit/main.py
@@ -281,6 +281,10 @@ def main():
         if debug_level > 0:
             traceback.print_exc()
         sys.exit(utils.STGIT_COMMAND_ERROR)
+    except SystemExit:
+        # Triggered by the option parser when it finds bad commandline
+        # parameters.
+        sys.exit(utils.STGIT_COMMAND_ERROR)
     except KeyboardInterrupt:
         sys.exit(utils.STGIT_GENERAL_ERROR)
     except:
Message 1 of 1 in “Handle commandline parsing errors gracefully”
  1. Handle commandline parsing errors gracefullyKarl Hasselström, Apr 20, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.