Skip to content

fix(tokenization): re-raise ImportError to allow RuntimeError/OSError fallback (#45459)#45460

Closed
cloudyun888 wants to merge 1 commit intohuggingface:mainfrom
cloudyun888:fix/tokenizer-protobuf-error-handling-45459
Closed

fix(tokenization): re-raise ImportError to allow RuntimeError/OSError fallback (#45459)#45460
cloudyun888 wants to merge 1 commit intohuggingface:mainfrom
cloudyun888:fix/tokenizer-protobuf-error-handling-45459

Conversation

@cloudyun888
Copy link
Copy Markdown

Summary

When protobuf is not installed, is a function call used as an expression. Because it is evaluated lazily when the try block raises, the resulting from the function itself bypasses the RuntimeError and OSError handlers below it, silently swallowing the original exception.

Changes

  • Replaced with
  • This allows the original exception (RuntimeError or OSError) to propagate to the appropriate fallback handler below
  • When protobuf is not installed, the user now gets the correct error message instead of an opaque protobuf ImportError

Testing

Fixes #45459

… fallback

When protobuf is not installed,  raises
ImportError before the try-block exception reaches the except-expression,
causing the RuntimeError and OSError handlers below to never execute.

Fix: catch ImportError directly and re-raise so downstream handlers run.

Fixes huggingface#45459
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

except import_protobuf_decode_error() hides real tokenizer errors when protobuf isn't installed

2 participants