Skip to contentSkip to conversation

send-error-report: improve debugging

PATCH Superseded [email protected] 2 participants 3 messages Apr 16, 2025 – Apr 18, 2025

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 send-error-report: improve debugging

From: Thomas Perrot <[email protected]>

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

---
 scripts/send-error-report | 28 ++++++++++++++++++++++++----
 1 file changed, 24 insertions(+), 4 deletions(-)
scripts/send-error-report +24 -4
index cfbcaa52cbc3..cdc1dfc5613a 100755
@@ -6,6 +6,7 @@
 # Copyright (C) 2013 Intel Corporation
 # Author: Andreea Proca <[email protected]>
 # Author: Michael Wood <[email protected]>
+# Author: Thomas Perrot <[email protected]>
 #
 # 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,13 +141,25 @@ def send_data(data, args):
         url = args.protocol+args.server+"/ClientPost/"
 
     req = urllib.request.Request(url, data=data, headers=headers)
+
+    if args.debug:
+        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'))
+    if args.debug:
+        log.debug(f"Response Status: {response.status}")
+        log.debug(f"Response Headers: {response.getheaders()}")
+        log.debug(f"Response Content: {response.read().decode('utf-8')}")
+    else:
+        print(response.read().decode('utf-8'))
 
 
 if __name__ == '__main__':
@@ -195,13 +208,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)
 
Signature · 1 line
2.49.0
#1 lore raw

Hi Thomas,

Quoted 32 lines · Thomas Perrot via lists.openembedded.org

From: Thomas Perrot <[email protected]>

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

---
  scripts/send-error-report | 28 ++++++++++++++++++++++++----
  1 file changed, 24 insertions(+), 4 deletions(-)
scripts/send-error-report +2 -1
index cfbcaa52cbc3..cdc1dfc5613a 100755
@@ -6,6 +6,7 @@
  # Copyright (C) 2013 Intel Corporation
  # Author: Andreea Proca <[email protected]>
  # Author: Michael Wood <[email protected]>
+# Author: Thomas Perrot <[email protected]>
  #
  # 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')

scripts/send-error-report def send_data(data, args): · line 149

Quoted 9 lines
scripts/send-error-report +6 -0
@@ -140,13 +141,25 @@ def send_data(data, args):
          url = args.protocol+args.server+"/ClientPost/"
 
      req = urllib.request.Request(url, data=data, headers=headers)
+
+    if args.debug:
+        log.debug(f"Request URL: {url}")
+        log.debug(f"Request Headers: {headers}")
+        log.debug(f"Request Data: {data.decode('utf-8')}")
+

Why only print log.debug if args.debug is set? Isn't that an unnecessary additional check considering the log.setLevel(logging.DEBUG) in main?

Quoted 5 lines
scripts/send-error-report +1 -1
      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}")

scripts/send-error-report def send_data(data, args): · line 162

Quoted 10 lines
scripts/send-error-report +7 -1
+        log.debug(f"Response Content: {e.read().decode('utf-8')}")
          sys.exit(1)
 
-    print(response.read().decode('utf-8'))
+    if args.debug:
+        log.debug(f"Response Status: {response.status}")
+        log.debug(f"Response Headers: {response.getheaders()}")
+        log.debug(f"Response Content: {response.read().decode('utf-8')}")
+    else:
+        print(response.read().decode('utf-8'))

Same remark here?

It's also a bit odd that the same info is going to be in different log levels depending on whether debug was enabled or not.

Cheers,
Quentin

#2 lore raw

Hello Quentin,

Quoted 41 lines · Quentin Schulz via lists.openembedded.org

Hi Thomas,

Quoted 38 lines · Thomas Perrot via lists.openembedded.org

From: Thomas Perrot <[email protected]>

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

---
  scripts/send-error-report | 28 ++++++++++++++++++++++++----

  1 file changed, 24 insertions(+), 4 deletions(-)
scripts/send-error-report +1 -0
index cfbcaa52cbc3..cdc1dfc5613a 100755
@@ -6,6 +6,7 @@
   # Copyright (C) 2013 Intel Corporation
   # Author: Andreea Proca <[email protected]>
   # Author: Michael Wood <[email protected]>
+# Author: Thomas Perrot <[email protected]>
   #
   # 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

scripts/send-error-report +1 -1
-version = "0.3"
+version = "0.4"


  log = logging.getLogger("send-error-report") logging.basicConfig(format='%(levelname)s: %(message)s')

scripts/send-error-report +0 -0
@@ -140,13 +141,25 @@ def send_data(data, args):

          url = args.protocol+args.server+"/ClientPost/"
      req = urllib.request.Request(url, data=data, headers=headers) +
+    if args.debug:

Quoted 8 lines
Quoted 4 lines

+        log.debug(f"Request URL: {url}")
+        log.debug(f"Request Headers: {headers}") +        log.debug(f"Request Data: {data.decode('utf-8')}") +

Why only print log.debug if args.debug is set? Isn't that an unnecessary
additional check considering the log.setLevel(logging.DEBUG) in main?

I agree that this check is redundant; it is due to a lack of attention. Thank you, and I will send a revised version.

Kind regards,
Thomas

Quoted 38 lines
Quoted 17 lines

      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'))
+    if args.debug:
+        log.debug(f"Response Status: {response.status}") +        log.debug(f"Response Headers: {response.getheaders()}") +        log.debug(f"Response Content:
{response.read().decode('utf-8')}")
+    else:
+        print(response.read().decode('utf-8'))

Same remark here?

It's also a bit odd that the same info is going to be in different log
levels depending on whether debug was enabled or not.

Cheers,
Quentin

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group. View/Reply Online (#215127):
https://lists.openembedded.org/g/openembedded-core/message/215127
Mute This Topic: https://lists.openembedded.org/mt/112292245/5443093
Group Owner: [email protected] Unsubscribe:
https://lists.openembedded.org/g/openembedded-core/unsub [
[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

Signature · 3 lines
Thomas Perrot, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com