diff mbox series

[v2] send-error-report: improve debugging

Message ID 20250418133504.932848-1-thomas.perrot@bootlin.com
State New
Headers show
Series [v2] send-error-report: improve debugging | expand

Commit Message

Thomas Perrot April 18, 2025, 1:35 p.m. UTC
From: Thomas Perrot <thomas.perrot@bootlin.com>

- add a debug mode
- print the request and the response when an error occurs.

Signed-off-by: Thomas Perrot <thomas.perrot@bootlin.com>
---

Changes in version 2:
- Drop the redundant checks

scripts/send-error-report | 25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)

--
2.49.0

Comments

Quentin Schulz April 18, 2025, 1:58 p.m. UTC | #1
Hi Thomas,

On 4/18/25 3:35 PM, Thomas Perrot via lists.openembedded.org wrote:
> From: Thomas Perrot <thomas.perrot@bootlin.com>
> 
> - add a debug mode
> - print the request and the response when an error occurs.
> 
> Signed-off-by: Thomas Perrot <thomas.perrot@bootlin.com>

Reviewed-by: Quentin Schulz <quentin.schulz@cherry.de>

Thanks!
Quentin
diff mbox series

Patch

diff --git a/scripts/send-error-report b/scripts/send-error-report
index cfbcaa52cbc3..9ea7160f52c4 100755
--- a/scripts/send-error-report
+++ b/scripts/send-error-report
@@ -6,6 +6,7 @@ 
 # Copyright (C) 2013 Intel Corporation
 # Author: Andreea Proca <andreea.b.proca@intel.com>
 # Author: Michael Wood <michael.g.wood@intel.com>
+# Author: Thomas Perrot <thomas.perrot@bootlin.com>
 #
 # SPDX-License-Identifier: GPL-2.0-only
 #
@@ -22,7 +23,7 @@  scripts_lib_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'li
 sys.path.insert(0, scripts_lib_path)
 import argparse_oe

-version = "0.3"
+version = "0.4"

 log = logging.getLogger("send-error-report")
 logging.basicConfig(format='%(levelname)s: %(message)s')
@@ -140,14 +141,21 @@  def send_data(data, args):
         url = args.protocol+args.server+"/ClientPost/"

     req = urllib.request.Request(url, data=data, headers=headers)
+
+    log.debug(f"Request URL: {url}")
+    log.debug(f"Request Headers: {headers}")
+    log.debug(f"Request Data: {data.decode('utf-8')}")
+
     try:
         response = urllib.request.urlopen(req)
     except urllib.error.HTTPError as e:
-        logging.error(str(e))
+        log.error(f"HTTP Error {e.code}: {e.reason}")
+        log.debug(f"Response Content: {e.read().decode('utf-8')}")
         sys.exit(1)

-    print(response.read().decode('utf-8'))
-
+    log.debug(f"Response Status: {response.status}")
+    log.debug(f"Response Headers: {response.getheaders()}")
+    log.info(response.read().decode('utf-8'))

 if __name__ == '__main__':
     arg_parse = argparse_oe.ArgumentParser(description="This scripts will send an error report to your specified error-report-web server.")
@@ -195,13 +203,20 @@  if __name__ == '__main__':
                            dest="protocol",
                            action="store_const", const="http://", default="https://")

-
+    arg_parse.add_argument("-d",
+                           "--debug",
+                           help="Enable debug mode to print request/response details",
+                           action="store_true")

     args = arg_parse.parse_args()

     if (args.json == False):
         print("Preparing to send errors to: "+args.server)

+    # Enable debugging if requested
+    if args.debug:
+        log.setLevel(logging.DEBUG)
+
     data = prepare_data(args)
     send_data(data, args)