mirror of
https://github.com/MadsLorentzen/ai-job-search.git
synced 2026-11-02 13:12:50 +00:00
fix(rank): report a tracker that is not UTF-8 instead of a traceback (#639)
* fix(rank): report a tracker that is not UTF-8 instead of a traceback A job_search_tracker.csv saved with a spreadsheet's plain "CSV" type is written in the ANSI code page, so one accented company name raised a UnicodeDecodeError traceback in `rank_state.py candidates` and stopped /rank at Step 1. Exit 1 with a one-line message instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * changelog: place the #639 entry under [Unreleased] Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Mads Lorentzen <madslorentzen_17@hotmail.com>
This commit is contained in:
3 files changed
+29
-5
No files matched your search
+10
-5
@@ -149,11 +149,16 @@ def tracker_pairs(path: Path) -> set[tuple[str, str]]:
|
||||
import csv
|
||||
|
||||
pairs = set()
|
||||
with path.open(encoding="utf-8-sig", newline="") as fh:
|
||||
for row in csv.DictReader(fh):
|
||||
company, role = norm(row.get("company")), norm(row.get("role"))
|
||||
if company:
|
||||
pairs.add((company, role))
|
||||
try:
|
||||
with path.open(encoding="utf-8-sig", newline="") as fh:
|
||||
for row in csv.DictReader(fh):
|
||||
company, role = norm(row.get("company")), norm(row.get("role"))
|
||||
if company:
|
||||
pairs.add((company, role))
|
||||
except UnicodeDecodeError:
|
||||
# A spreadsheet's plain "CSV" save writes the ANSI code page (cp1252 on
|
||||
# most Western installs), so any accented company name stops decoding.
|
||||
sys.exit(f"{path} is not UTF-8 text - re-save it as CSV UTF-8")
|
||||
return pairs
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user