예외 처리 개선: ValueError와 UnicodeDecodeError 추가

- str.format() 예외 처리에 ValueError 추가 (템플릿 중괄호 불균형)
- .decode(utf-8) 예외 처리에 ValueError 추가 (UnicodeDecodeError는 ValueError 서브클래스)
- URLError/TimeoutError는 이미 OSError 서브클래스이므로 정리 (주석 추가)
- ai_pick_cuts는 모든 실패에 예외 없이 {} 반환하는 계약 이행

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
hehihoho3@gmail.com 2026-08-04 12:02:36 +09:00
parent 7cb70cc33a
commit ee30e87bb4

View File

@ -133,7 +133,7 @@ def ai_pick_cuts(cuts, comments, quotas, *, model: str = AI_MODEL,
try:
prompt = prompts.load_recommend().format(
cuts=_cut_lines(cuts), comments=_candidate_lines(comments), k=k)
except (KeyError, IndexError, OSError): # 사용자가 프롬프트를 깨뜨린 경우
except (KeyError, IndexError, ValueError, OSError): # 사용자가 프롬프트를 깨뜨린 경우
return {}
body = {
"contents": [{"parts": [{"text": prompt}]}],
@ -149,7 +149,7 @@ def ai_pick_cuts(cuts, comments, quotas, *, model: str = AI_MODEL,
with urllib.request.urlopen(req, timeout=timeout) as resp:
data = json.loads(resp.read().decode("utf-8"))
raw = data["candidates"][0]["content"]["parts"][0]["text"]
except (urllib.error.URLError, KeyError, IndexError, TimeoutError,
json.JSONDecodeError, OSError):
except (KeyError, IndexError, json.JSONDecodeError, ValueError,
OSError): # URLError, TimeoutError are OSError subclasses; ValueError covers UnicodeDecodeError
return {} # 429 포함 — 폴백은 호출부 몫
return _parse_ai(raw)