Skip to content

Better error handling through improved Display and Error impls #616

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 15, 2025

Conversation

H2CO3
Copy link
Contributor

@H2CO3 H2CO3 commented Jun 13, 2025

What does this PR do?

This improves user-facing impls (primarily related to error reporting) such as Display and Error, in the following ways:

  • manual Display impls are provided when user-visible descriptions are needed, and {} formatting is used instead of {:? where appropriate. Debug is not suitable for this purpose, as its output is neither human-readable nor stable nor reliable.
  • In particular, Debug formatting may very well print absolutely NOTHING at all, so it's basically completely unreliable, and that is on purpose. See e.g. debug-fmt-detail option rust-lang/rust#123940 for details.
  • Error impls are provided for all error-like types where missing, and the source() method is implemented in a more useful manner where possible, so as to provide error chaining/causality information.
  • Underlying errors are stored in error types when appropriate.
  • Paths are displayed as intended, i.e., using the .display() method instead of Debug-formatting.
  • The Display impl for the Disp type is simplified.
  • Some unnecessary allocations of temporary strings (.to_string() and format!()) are eliminated.

The Python bindings are also updated according to these principles. The Python API is not affected.

@Narsil Narsil merged commit 3012241 into huggingface:main Jun 15, 2025
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