Skip to content

Commit

Permalink
Catch UnicodeDecodeError in JLC order number check (#559)
Browse files Browse the repository at this point in the history
* Catch UnicodeDecodeError in JLC order number check

* open with errors=replace
  • Loading branch information
Bouni authored Dec 16, 2024
1 parent 43981c0 commit cf022dd
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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."""
Expand Down Expand Up @@ -823,11 +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"
)
return True

def generate_fabrication_data(self, *_):
Expand Down

0 comments on commit cf022dd

Please sign in to comment.