feat: 异常树 error_code 类属性(对齐 api-design §7 错误码)

This commit is contained in:
lhl
2026-08-09 13:38:59 +08:00
parent a0a40afd45
commit f61e7dadb7
3 changed files with 23 additions and 3 deletions
+15 -1
View File
@@ -18,4 +18,18 @@ def test_error_hierarchy():
def test_error_message_roundtrip():
e = LLMTimeoutError("timeout!")
assert str(e) == "timeout!"
assert str(e) == "timeout!"
def test_error_code_class_attributes():
# error_code 与 api-design §7 错误码表一一对应(机器可读事实源)
assert LLMError.error_code is None
assert LLMTimeoutError.error_code == "LLM_TIMEOUT"
assert LLMNetworkError.error_code == "LLM_NETWORK_ERROR"
assert LLMNotConfiguredError.error_code == "LLM_NOT_CONFIGURED"
assert LLMResponseError.error_code == "LLM_PARSE_ERROR"
def test_error_code_inherited_by_instance():
e = LLMNetworkError("network")
assert e.error_code == "LLM_NETWORK_ERROR"