Test that server-side exceptions are properly wrapped in RPCError with details.
(self)
| 252 | pass |
| 253 | |
| 254 | def test_task_error(self): |
| 255 | """Test that server-side exceptions are properly wrapped in RPCError with details.""" |
| 256 | |
| 257 | class App: |
| 258 | |
| 259 | def hello(self): |
| 260 | raise ValueError("Test error message") |
| 261 | |
| 262 | def divide_by_zero(self): |
| 263 | return 1 / 0 |
| 264 | |
| 265 | def custom_exception(self): |
| 266 | raise TestRpcError.CustomError("Custom error occurred") |
| 267 | |
| 268 | addr = get_unique_ipc_addr() |
| 269 | with RPCServer(App()) as server: |
| 270 | server.bind(addr) |
| 271 | server.start() |
| 272 | time.sleep(0.1) |
| 273 | with RPCClient(addr) as client: |
| 274 | # Test ValueError handling |
| 275 | with pytest.raises(RPCError) as exc_info: |
| 276 | client.hello().remote() |
| 277 | |
| 278 | error = exc_info.value |
| 279 | assert "Test error message" in str(error) |
| 280 | assert error.cause is not None |
| 281 | assert isinstance(error.cause, ValueError) |
| 282 | assert error.traceback is not None |
| 283 | assert "ValueError: Test error message" in error.traceback |
| 284 | |
| 285 | # Test ZeroDivisionError handling |
| 286 | with pytest.raises(RPCError) as exc_info: |
| 287 | client.divide_by_zero().remote() |
| 288 | |
| 289 | error = exc_info.value |
| 290 | assert "division by zero" in str(error) |
| 291 | assert error.cause is not None |
| 292 | assert isinstance(error.cause, ZeroDivisionError) |
| 293 | assert error.traceback is not None |
| 294 | |
| 295 | # Test custom exception handling |
| 296 | with pytest.raises(RPCError) as exc_info: |
| 297 | client.custom_exception().remote() |
| 298 | |
| 299 | error = exc_info.value |
| 300 | assert "Custom error occurred" in str(error) |
| 301 | assert error.cause is not None |
| 302 | assert error.traceback is not None |
| 303 | |
| 304 | def test_shutdown_cancelled_error(self): |
| 305 | """Test that pending requests are cancelled with RPCCancelled when server shuts down.""" |
nothing calls this directly
no test coverage detected