From 55af02374da8537fcd3e8d3aa52cdb84226fc4ae Mon Sep 17 00:00:00 2001
From: Marko Mecina <marko.mecina@univie.ac.at>
Date: Sat, 10 Dec 2022 18:44:56 +0100
Subject: [PATCH] better failure handling for incompatible monitor sets

+ fix deprecation warning
---
 Ccs/monitor.py      | 12 ++++++++++--
 Ccs/poolview_sql.py |  2 +-
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/Ccs/monitor.py b/Ccs/monitor.py
index 61792d5..3043fb5 100644
--- a/Ccs/monitor.py
+++ b/Ccs/monitor.py
@@ -1006,7 +1006,11 @@ class MonitorSetupDialog(Gtk.Dialog):
         self.useriter = parameter_model.append(None, ['UDEF packets', None])
         for userpacket in udpkts:
             st, sst, apid, sid = map(cfl.str_to_int, userpacket.split('-'))
-            sid_off, sid_bitlen = cfl.get_sid(st, sst, apid)
+            sidinfo = cfl.get_sid(st, sst, apid)
+            if sidinfo is None:
+                self.logger.error('UDEF packet {} not compatible with SID definitions'.format(userpacket))
+                continue
+            sid_off, sid_bitlen = sidinfo
             pktdef = json.loads(udpkts[userpacket])
             pktiter = parameter_model.append(self.useriter, [pktdef[0], None])
             for userpar in pktdef[1]:
@@ -1064,7 +1068,11 @@ class MonitorSetupDialog(Gtk.Dialog):
                 pnames = {eval(par)[0]: par for par in slots}
 
                 for par in pnames:
-                    self.slots[i][3].append([par.split(':')[1], pnames[par]])
+                    try:
+                        self.slots[i][3].append([par.split(':')[1], pnames[par]])
+                    except Exception as err:
+                        self.logger.error('Incompatible parameter {} in set {}'.format(par, entry))
+                        continue
             dbcon.close()
 
         else:
diff --git a/Ccs/poolview_sql.py b/Ccs/poolview_sql.py
index f6800cd..2480f12 100644
--- a/Ccs/poolview_sql.py
+++ b/Ccs/poolview_sql.py
@@ -2476,7 +2476,7 @@ class TMPoolView(Gtk.Window):
 
         box = Gtk.HBox()
 
-        name = Gtk.Label(decoder_name.get_active_text())
+        name = Gtk.Label(label=decoder_name.get_active_text())
         name.set_tooltip_text('bytes {}-{}'.format(bytepos, bytepos + bytelen - 1))
         hexa = Gtk.Label()
         uint = Gtk.Label()
-- 
GitLab