Skip to content

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
xanderlent added a commit to xanderlent/safetensors that referenced this pull request Aug 2, 2025
These tests look for error messages which changed in commit 3012241/PR#616.

Fixes: 3012241 ("Better error handling through improved `Display` and `Error` impls (huggingface#616)")
Narsil pushed a commit that referenced this pull request Aug 4, 2025
These tests look for error messages which changed in commit 3012241/PR#616.

Fixes: 3012241 ("Better error handling through improved `Display` and `Error` impls (#616)")
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