From 54024f3e7aaa3e4bfca13cf4da9a197507242c18 Mon Sep 17 00:00:00 2001 From: bouni Date: Mon, 16 Dec 2024 12:47:29 +0100 Subject: [PATCH 1/2] Catch UnicodeDecodeError in JLC order number check --- mainwindow.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mainwindow.py b/mainwindow.py index 4b18b29..e38b4a2 100644 --- a/mainwindow.py +++ b/mainwindow.py @@ -828,6 +828,8 @@ def check_order_number(self): return "JLCJLCJLCJLC" in data except OSError: pass + except UnicodeDecodeError: + self.logger.debug("Failed to check JLC order number due to UnicodeDecodeError") return True def generate_fabrication_data(self, *_): From 526379b7bbc65a77f1be49645d18069534ecae30 Mon Sep 17 00:00:00 2001 From: bouni Date: Mon, 16 Dec 2024 12:52:07 +0100 Subject: [PATCH 2/2] open with errors=replace --- mainwindow.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/mainwindow.py b/mainwindow.py index e38b4a2..3bd90e9 100644 --- a/mainwindow.py +++ b/mainwindow.py @@ -383,7 +383,11 @@ def __init__(self, parent, kicad_provider=KicadProvider()): align=wx.ALIGN_CENTER, ) params = self.footprint_list.AppendTextColumn( - "LCSC Params", 10, width=150, mode=dv.DATAVIEW_CELL_INERT, align=wx.ALIGN_CENTER + "LCSC Params", + 10, + width=150, + mode=dv.DATAVIEW_CELL_INERT, + align=wx.ALIGN_CENTER, ) lcsc = self.footprint_list.AppendTextColumn( "LCSC", 3, width=100, mode=dv.DATAVIEW_CELL_INERT, align=wx.ALIGN_CENTER @@ -544,7 +548,9 @@ def assign_parts(self, e): fp = board.FindFootprintByReference(reference) set_lcsc_value(fp, e.lcsc) params = params_for_part(self.library.get_part_details(e.lcsc)) - self.partlist_data_model.set_lcsc(reference, e.lcsc, e.type, e.stock, params) + self.partlist_data_model.set_lcsc( + reference, e.lcsc, e.type, e.stock, params + ) def display_message(self, e): """Dispaly a message with the data from the event.""" @@ -823,13 +829,16 @@ def select_part(self, *_): def check_order_number(self): """Verify that the JLC order number placeholder is present.""" try: - with open(self.pcbnew.GetBoard().GetFileName()) as f: + # We open with errors="replace because we're only interested in the occurance of the JLC magic string" + with open(self.pcbnew.GetBoard().GetFileName(), errors="replace") as f: data = f.read() return "JLCJLCJLCJLC" in data except OSError: pass except UnicodeDecodeError: - self.logger.debug("Failed to check JLC order number due to UnicodeDecodeError") + self.logger.debug( + "Failed to check JLC order number due to UnicodeDecodeError" + ) return True def generate_fabrication_data(self, *_):