]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
manager: cli: print error messages to sys.stderr
authorVladimír Čunát <vladimir.cunat@nic.cz>
Thu, 3 Aug 2023 09:30:43 +0000 (11:30 +0200)
committerAleš Mrázek <ales.mrazek@nic.cz>
Fri, 4 Aug 2023 13:15:14 +0000 (13:15 +0000)
This is important for cases like
  kresctl convert file1 > file2
I grepped for '\<print(' and converted all error states (I think).

manager/knot_resolver_manager/cli/cmd/config.py
manager/knot_resolver_manager/cli/cmd/convert.py
manager/knot_resolver_manager/cli/cmd/metrics.py
manager/knot_resolver_manager/cli/cmd/reload.py
manager/knot_resolver_manager/cli/cmd/schema.py
manager/knot_resolver_manager/cli/cmd/stop.py
manager/knot_resolver_manager/cli/cmd/validate.py
manager/knot_resolver_manager/utils/requests.py

index 28994d8bc6211ae7372160375cbede8972ce69cc..a788f38d3863f5033895d5909981e828b6b4a386 100644 (file)
@@ -244,7 +244,7 @@ class ConfigCommand(Command):
         response = request(method, url, json_dump(new_config) if new_config else None)
 
         if response.status != 200:
-            print(response)
+            print(response, file=sys.stderr)
             sys.exit(1)
 
         if self.operation == Operations.GET and self.file:
index 9c7e5d2a76a842cfa438c4256c31f87106f0ffa5..aab2740a956a4b50c02b566e02de18c73173ed9b 100644 (file)
@@ -64,7 +64,7 @@ class ConvertCommand(Command):
             lua = KresConfig(parsed).render_lua()
             reset_global_validation_context()
         except (DataParsingError, DataValidationError) as e:
-            print(e)
+            print(e, file=sys.stderr)
             sys.exit(1)
 
         if self.output_file:
index 8b9c8028e5dab932fe5b40bc9782dc76ce30226c..c924ef5e72bea1df98c862cc3d759eba335faca6 100644 (file)
@@ -41,5 +41,5 @@ class MetricsCommand(Command):
             else:
                 print(response.body)
         else:
-            print(response)
+            print(response, file=sys.stderr)
             sys.exit(1)
index 5818a54c134cf7e0ee50a55f5139738346a96085..e0d288962c46e534a9c8623cb70569b537fad80c 100644 (file)
@@ -32,5 +32,5 @@ class ReloadCommand(Command):
         response = request("POST", f"{args.socket}/reload")
 
         if response.status != 200:
-            print(response)
+            print(response, file=sys.stderr)
             sys.exit(1)
index 0d8a032426129bc8491cf50a082207fbba39dda1..790da7fdbb975ea0d7222c8085527005cc3531af 100644 (file)
@@ -42,7 +42,7 @@ class SchemaCommand(Command):
         if self.live:
             response = request("GET", f"{args.socket}/schema")
             if response.status != 200:
-                print(response)
+                print(response, file=sys.stderr)
                 sys.exit(1)
             schema = response.body
         else:
index e792dec33be87ab7723c464ca03e9971cfead0d5..f3539def8947951002dd5ea94eefbfb07b7cc7df 100644 (file)
@@ -24,7 +24,7 @@ class StopCommand(Command):
         response = request("POST", f"{args.socket}/stop")
 
         if response.status != 200:
-            print(response)
+            print(response, file=sys.stderr)
             sys.exit(1)
 
     @staticmethod
index 0770d7573b303eece06745e960d1a13e0cd23318..aacd198969c7d5b4d4b86cdea5aaa7dd35105209 100644 (file)
@@ -59,5 +59,5 @@ class ValidateCommand(Command):
             KresConfig(try_to_parse(data))
             reset_global_validation_context()
         except (DataParsingError, DataValidationError) as e:
-            print(e)
+            print(e, file=sys.stderr)
             sys.exit(1)
index ab95c5d25c05763e9b530051ddeb79cad229402b..db29f85e024638e4f7aa378657a401fd62e406f2 100644 (file)
@@ -38,11 +38,14 @@ def request(
         return Response(err.code, err.read().decode("utf8"))
     except URLError as err:
         if err.errno == 111 or isinstance(err.reason, ConnectionRefusedError):
-            print("Connection refused.")
-            print(f"\tURL: {url}")
-            print("Is the URL correct?")
-            print("\tUnix socket would start with http+unix:// and URL encoded path.")
-            print("\tInet sockets would start with http:// and domain or ip")
+            msg = f"""
+                Connection refused.
+                \tURL: {url}
+                Is the URL correct?
+                \tUnix socket would start with http+unix:// and URL encoded path.
+                \tInet sockets would start with http:// and domain or ip
+            """
+            print(msg, file=sys.stderr)
         else:
             print(f"{err}: url={url}", file=sys.stderr)
         sys.exit(1)