-
Notifications
You must be signed in to change notification settings - Fork 0
Implement error displays #169
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
leynos
merged 6 commits into
main
from
codex/implement-display-and-error-for-pusherror-and-wireframeerror
Jul 4, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b99cf38
Implement error displays
leynos 7f7c2f0
Return protocol source error
leynos 664c017
Make module comment more descriptive.
leynos 2205dd9
Add backticks
leynos 1574057
Use rstest to eliminate duplication and ease future growth
leynos 99d55e9
Fix formatting
leynos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -89,3 +89,24 @@ impl<E> WireframeError<E> { | |
| #[must_use] | ||
| pub fn from_io(e: std::io::Error) -> Self { WireframeError::Io(e) } | ||
| } | ||
|
|
||
| impl<E: std::fmt::Debug> std::fmt::Display for WireframeError<E> { | ||
| fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
| match self { | ||
| WireframeError::Io(e) => write!(f, "transport error: {e}"), | ||
| WireframeError::Protocol(e) => write!(f, "protocol error: {e:?}"), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl<E> std::error::Error for WireframeError<E> | ||
| where | ||
| E: std::fmt::Debug + std::error::Error + 'static, | ||
| { | ||
| fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: Error::source returns None for Protocol even if E might implement Error. Consider returning Some(e) for the Protocol variant if E implements Error. If returning None is intentional, please document the reasoning. |
||
| match self { | ||
| WireframeError::Io(e) => Some(e), | ||
| WireframeError::Protocol(e) => Some(e), | ||
| } | ||
| } | ||
| } | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| //! Tests for Display and Error trait implementations on error types. | ||
| //! | ||
| //! Verifies that error types provide human-readable messages via Display | ||
| //! and correctly expose underlying error sources via `Error::source`. | ||
|
|
||
| use std::error::Error; | ||
|
|
||
| use wireframe::{push::PushError, response::WireframeError}; | ||
|
|
||
| #[rstest::rstest] | ||
| #[case(PushError::QueueFull, "push queue full")] | ||
| #[case(PushError::Closed, "push queue closed")] | ||
| fn push_error_messages(#[case] err: PushError, #[case] expected: &str) { | ||
| assert_eq!(err.to_string(), expected); | ||
| } | ||
|
|
||
| #[derive(Debug)] | ||
| struct ProtoErr; | ||
|
|
||
| impl std::fmt::Display for ProtoErr { | ||
| fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.write_str("boom") } | ||
| } | ||
|
|
||
| impl std::error::Error for ProtoErr {} | ||
|
|
||
| #[test] | ||
| fn wireframe_error_messages() { | ||
| let io_error = std::io::Error::other("socket closed"); | ||
| let io = WireframeError::<ProtoErr>::Io(io_error); | ||
| assert_eq!(io.to_string(), "transport error: socket closed"); | ||
|
|
||
| let source = io.source().expect("io variant must have source"); | ||
| assert_eq!(source.to_string(), "socket closed"); | ||
|
|
||
| let proto = WireframeError::Protocol(ProtoErr); | ||
| assert_eq!(proto.to_string(), "protocol error: ProtoErr"); | ||
|
|
||
| let source = proto.source().expect("protocol variant must have source"); | ||
| assert_eq!(source.to_string(), "boom"); | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.