]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
suricatasc: handle exceptions in caller
authorShivani Bhardwaj <shivani@oisf.net>
Thu, 22 Jun 2023 12:21:05 +0000 (17:51 +0530)
committerVictor Julien <vjulien@oisf.net>
Tue, 27 Jun 2023 07:33:49 +0000 (09:33 +0200)
python/bin/suricatasc

index dc108da4af5844ce4ff74ba829fea17bafadc095..d090f856f54d6e43e554637b17353c50eef4eef3 100755 (executable)
@@ -1,6 +1,6 @@
 #! /usr/bin/env python
 #
-# Copyright(C) 2013-2022 Open Information Security Foundation
+# Copyright(C) 2013-2023 Open Information Security Foundation
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -69,8 +69,16 @@ except SuricataReturnException as err:
     sys.exit(1)
 
 if args.command:
-    (command, arguments) = sc.parse_command(args.command)
-    res = sc.send_command(command, arguments)
+    try:
+        (command, arguments) = sc.parse_command(args.command)
+    except SuricataCommandException as err:
+        print(err.value)
+        sys.exit(1)
+    try:
+        res = sc.send_command(command, arguments)
+    except (SuricataCommandException, SuricataReturnException) as err:
+        print(err.value)
+        sys.exit(1)
     print(json.dumps(res))
     sc.close()
     if res['return'] == 'OK':