Change in osmocom-bb[master]: trx_toolkit/data_if.py: enrich encoding/decoding error messages

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

fixeria gerrit-no-reply at lists.osmocom.org
Fri Apr 30 20:34:12 UTC 2021


fixeria has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmocom-bb/+/24021 )


Change subject: trx_toolkit/data_if.py: enrich encoding/decoding error messages
......................................................................

trx_toolkit/data_if.py: enrich encoding/decoding error messages

The keyword 'exc_info' of the logging API allows us to see a lot more
detailed information about the exception being caught, for example:

'''
  [ERROR] data_if.py:68 Failed to parse a TRXD Tx message from r=127.0.0.1:5802
  Traceback (most recent call last):
    File "/home/fixeria/trx_toolkit/codec.py", line 329, in _from_bytes
      offset += f.from_bytes(vals, data[offset:])
    File "/home/fixeria/trx_toolkit/codec.py", line 94, in from_bytes
      self._from_bytes(vals, data[:length])
    File "/home/fixeria/trx_toolkit/codec.py", line 239, in _from_bytes
      f.dec_val(vals, blob)
    File "/home/fixeria/trx_toolkit/codec.py", line 287, in dec_val
      raise DecodeError('Unexpected value %d, expected %d'
  codec.DecodeError: Unexpected value 6, expected 2

  The above exception was the direct cause of the following exception:

  Traceback (most recent call last):
    File "/home/fixeria/trx_toolkit/data_if.py", line 66, in recv_tx_msg
      msg.from_bytes(data)
    File "/home/fixeria/trx_toolkit/data_msg.py", line 201, in from_bytes
      self.codec._from_bytes(self.c, msg)
    File "/home/fixeria/trx_toolkit/codec.py", line 332, in _from_bytes
      raise DecodeError(self, f, offset) from e
  codec.DecodeError: (<trxd_proto.PDUv2Tx object at 0x7facbd079220>,
                      <trxd_proto.Header object at 0x7facbd076b50>, 0)
'''

>From this example it can be seen that the 'codec.DecodeError' exception
has occured while parsing the 'Header' part of the 'PDUv2Tx' at offset
0, and caused by an unexpected TRXD PDU version value.

Change-Id: Iec80890e52f7aa24c145356b5f2e1f66a47fbd4c
Related: OS#4006, SYS#4895
---
M src/target/trx_toolkit/data_if.py
1 file changed, 9 insertions(+), 9 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmocom-bb refs/changes/21/24021/1

diff --git a/src/target/trx_toolkit/data_if.py b/src/target/trx_toolkit/data_if.py
index f754c6c..5e8fe6e 100644
--- a/src/target/trx_toolkit/data_if.py
+++ b/src/target/trx_toolkit/data_if.py
@@ -64,9 +64,9 @@
 		try:
 			msg = TxMsg(self._hdr_ver)
 			msg.from_bytes(data)
-		except:
-			log.error("Failed to parse a TRXD Tx message "
-				"from R:%s:%u" % (self.remote_addr, self.remote_port))
+		except Exception as e:
+			log.error("Failed to parse a TRXD Tx message from r=%s:%u",
+				  self.remote_addr, self.remote_port, exc_info=e)
 			return None
 
 		return msg
@@ -79,9 +79,9 @@
 		try:
 			msg = RxMsg(self._hdr_ver)
 			msg.from_bytes(data)
-		except:
-			log.error("Failed to parse a TRXD Rx message "
-				"from R:%s:%u" % (self.remote_addr, self.remote_port))
+		except Exception as e:
+			log.error("Failed to parse a TRXD Rx message from r=%s:%u",
+				  self.remote_addr, self.remote_port, exc_info=e)
 			return None
 
 		return msg
@@ -89,9 +89,9 @@
 	def send_msg(self, msg: RxMsg) -> None:
 		try:
 			payload = msg.to_bytes()
-		except ValueError as e:
-			log.error("Failed to encode a TRXD message ('%s') "
-				"due to error: %s" % (msg.desc_hdr(), e))
+		except Exception as e:
+			log.error("Failed to encode a TRXD message ('%s')",
+				  msg.desc_hdr(), exc_info=e)
 			# TODO: we may want to send a NOPE.ind here
 			return
 

-- 
To view, visit https://gerrit.osmocom.org/c/osmocom-bb/+/24021
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmocom-bb
Gerrit-Branch: master
Gerrit-Change-Id: Iec80890e52f7aa24c145356b5f2e1f66a47fbd4c
Gerrit-Change-Number: 24021
Gerrit-PatchSet: 1
Gerrit-Owner: fixeria <vyanitskiy at sysmocom.de>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210430/d6a389d0/attachment.htm>


More information about the gerrit-log mailing list