Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch UnicodeDecodeError in JLC order number check #559

Merged
merged 2 commits into from
Dec 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading