Eliaaazzz opened a new pull request, #58515: URL: https://github.com/apache/spark/pull/58515
### What changes were proposed in this pull request? `_extract_jvm_stacktrace` in `pyspark/errors/exceptions/connect.py` follows the `cause_idx` chain from `FetchErrorDetailsResponse` recursively, without validating the index. This PR walks the chain iteratively instead and stops when the next index is out of range or has already been visited, so each error is formatted at most once. The Scala client has a similar unguarded recursion in `GrpcExceptionConverter.errorsToThrowable`; this PR only covers the Python client. ### Why are the changes needed? If the error details returned by `FetchErrorDetails` contain a malformed cause chain, the client crashes inside error conversion and the original server error is lost: - a cyclic `cause_idx` (two errors pointing at each other, or an error listed as its own cause) raises `RecursionError: maximum recursion depth exceeded` - an out-of-range `cause_idx` raises `IndexError: list index out of range` Reproducible by calling `convert_exception` with a `FetchErrorDetailsResponse` where `errors[0].cause_idx = 1` and `errors[1].cause_idx = 0`. ### Does this PR introduce _any_ user-facing change? Only for malformed error details: the client now raises the converted server exception instead of `RecursionError`/`IndexError`. Well-formed cause chains are formatted exactly as before. ### How was this patch tested? Added `test_convert_exception_with_malformed_cause_chain` to `pyspark.errors.tests.test_connect_errors_conversion` covering the mutual cycle, the self-cycle, and the out-of-range case. All tests in the module pass: ``` python -m pytest python/pyspark/errors/tests/test_connect_errors_conversion.py 13 passed ``` ### Was this patch authored or co-authored using generative AI tooling? Generated-by: Claude Code -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
