Skip to content

Exception translation logic creates recursion in some cases #442

@isidentical

Description

@isidentical

raise translate_boto_error(captured_error) from captured_error is a common pattern in the codebase, though the problem with this is that translate_boto_error might return the same exception and it would create a recursion of __cause__ since x_exception.__cause__ is itself (is x_exception) which would prevent anyone from traversing it easily;
https://github.com/dask/s3fs/blob/1333a8d46d38fd8d4c85536972cafcba998fd62e/s3fs/core.py#L253

This pattern can be replaced via

new_exc = translate_boto_error(exc)
if new_exc is exc:
     raise exc
else:
    raise new_exc from exc

but since it would create a lot of code duplication, I think a better way would be directly using raise translate_boto_error(exc) directly and setting the __cause__ there to the new exception so that we can avoid the recursion and also the code duplication at the same time.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions