Skip to content

Commit d9666fd

Browse files
committed
fix test
1 parent aeafa13 commit d9666fd

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

eval_protocol/exceptions.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,17 +160,18 @@ class ScoreInvalidError(EvalProtocolError):
160160
}
161161

162162

163-
def exception_for_status_code(code: int) -> Optional[EvalProtocolError]:
163+
def exception_for_status_code(code: int, message: str = "") -> Optional[EvalProtocolError]:
164164
"""
165165
Create an exception instance for a given status code.
166166
167167
Args:
168168
code: Status code from Status.Code enum
169+
message: Optional error message to include in the exception
169170
170171
Returns:
171172
Exception instance or None if code is OK (0)
172173
"""
173174
exception_class = STATUS_CODE_TO_EXCEPTION.get(code)
174175
if exception_class is None:
175176
return None
176-
return exception_class()
177+
return exception_class(message) if message else exception_class()

eval_protocol/pytest/remote_rollout_processor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ def _get_status() -> Dict[str, Any]:
161161
f"Found Fireworks log for rollout {row.execution_metadata.rollout_id} with status code {status_code}"
162162
)
163163

164-
# Create and raise exception if appropriate
165-
exception = exception_for_status_code(status_code)
164+
# Create and raise exception if appropriate, preserving original message
165+
exception = exception_for_status_code(status_code, status_message)
166166
if exception is not None:
167167
raise exception
168168

tests/test_exceptions.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,3 +348,24 @@ def test_integration_with_retry_logic():
348348
assert exception_class in DEFAULT_RETRYABLE_EXCEPTIONS, (
349349
f"{exception_class.__name__} should be in DEFAULT_RETRYABLE_EXCEPTIONS for retry support"
350350
)
351+
352+
353+
def test_exception_message_preservation():
354+
"""Test that error messages are properly preserved in exceptions."""
355+
test_cases = [
356+
(13, "test error", InternalError),
357+
(5, "Model xyz not found", NotFoundError),
358+
(7, "Invalid API key", PermissionDeniedError),
359+
]
360+
361+
for status_code, message, expected_exception_class in test_cases:
362+
# Test with message
363+
exception = exception_for_status_code(status_code, message)
364+
assert exception is not None
365+
assert isinstance(exception, expected_exception_class)
366+
assert str(exception) == message, f"Exception should preserve message '{message}'"
367+
368+
# Test without message (should still work)
369+
exception_no_msg = exception_for_status_code(status_code)
370+
assert exception_no_msg is not None
371+
assert isinstance(exception_no_msg, expected_exception_class)

0 commit comments

Comments
 (0)