Skip to content

Fix torchcodec import error handling to catch all exceptions#1108

Merged
helloyongyang merged 1 commit into
mainfrom
fix-torchcodec-import
Jun 1, 2026
Merged

Fix torchcodec import error handling to catch all exceptions#1108
helloyongyang merged 1 commit into
mainfrom
fix-torchcodec-import

Conversation

@black-eleven
Copy link
Copy Markdown
Contributor

No description provided.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines 16 to +17
import torchcodec # noqa: F401
except ImportError:
except Exception:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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.

Suggested change
import torchcodec # noqa: F401
except ImportError:
except Exception:
import torchcodec # noqa: F401
import torchaudio # noqa: F401
except Exception:

@helloyongyang helloyongyang merged commit 2e0e599 into main Jun 1, 2026
2 checks passed
@helloyongyang helloyongyang deleted the fix-torchcodec-import branch June 1, 2026 06:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants