Fix torchcodec import error handling to catch all exceptions#1108
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the exception handling in _torchaudio_decode_available to catch general exceptions when importing torchcodec. The reviewer points out that the function should also verify that torchaudio is importable to prevent an unhandled ImportError later in load_audio_file if torchcodec is present but torchaudio is missing.
| import torchcodec # noqa: F401 | ||
| except ImportError: | ||
| except Exception: |
There was a problem hiding this comment.
While catching Exception correctly handles potential C++ binding initialization errors from torchcodec, _torchaudio_decode_available() should also verify that torchaudio is importable. Currently, if torchcodec is installed but torchaudio is missing, _torchaudio_decode_available() will return True, leading to an unhandled ImportError when load_audio_file attempts to import torchaudio on line 32.
| import torchcodec # noqa: F401 | |
| except ImportError: | |
| except Exception: | |
| import torchcodec # noqa: F401 | |
| import torchaudio # noqa: F401 | |
| except Exception: |
No description provided.