Use specific Utf8Error for Message::{into_text, to_text}#535
Open
sehyunsix wants to merge 1 commit intosnapview:masterfrom
Open
Use specific Utf8Error for Message::{into_text, to_text}#535sehyunsix wants to merge 1 commit intosnapview:masterfrom
sehyunsix wants to merge 1 commit intosnapview:masterfrom
Conversation
The `into_text` and `to_text` methods on `Message` can only produce UTF-8 errors, so return `std::str::Utf8Error` instead of the generic `tungstenite::Error`. This aligns with `Frame::into_text` and `Frame::to_text` which already use specific error types. Closes snapview#438 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Member
daniel-abramov
left a comment
There was a problem hiding this comment.
I agree it would be better to have some consistency in the error types.
I wonder if we could simply change the type of Error::Utf8(String) to Error::Utf8(Utf8Error). To my memory, the last change in this direction was done in 255aaa2. Perhaps we could just use Utf8Error instead? That would unify the error's return type across the crate. I think we use our own Result<X, Error> pretty much everywhere in the public API, except probably in parts of Frame (which is arguably a bit lower-level).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Message::into_text()return type fromResult<Utf8Bytes>toResult<Utf8Bytes, Utf8Error>Message::to_text()return type fromResult<&str>toResult<&str, Utf8Error>Frame::into_text()andFrame::to_text()which already use specific error typesCloses #438
Notes
This is a breaking change for callers that explicitly annotate the error type as
tungstenite::Error. However, callers using?in functions returningtungstenite::Resultwill continue to work sinceFrom<Utf8Error> for tungstenite::Erroris already implemented.Test plan
cargo checkpasses🤖 Generated with Claude Code