-
-
Notifications
You must be signed in to change notification settings - Fork 139
zb Provide a better error message for a failed connection that uses an address #1480
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -5,6 +5,7 @@ use zvariant::{Error as VariantError, ObjectPath}; | |||||
| use crate::{ | ||||||
| fdo, | ||||||
| message::{Message, Type}, | ||||||
| Address, | ||||||
| }; | ||||||
|
|
||||||
| /// The error type for `zbus`. | ||||||
|
|
@@ -20,6 +21,8 @@ pub enum Error { | |||||
| Address(String), | ||||||
| /// An I/O error. | ||||||
| InputOutput(Arc<io::Error>), | ||||||
| /// An I/O error with the related URI. | ||||||
|
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. Let's be a bit more descriptive here and document the arguments (especially since we don't name them in here, which I know is not ideal). |
||||||
| InputOutputAddress(Arc<io::Error>, Address), | ||||||
|
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. This a very strange name IMO that will confuse people. I actually suggested a specific name in #14778: |
||||||
| /// Invalid message field. | ||||||
| InvalidField, | ||||||
| /// Data too large. | ||||||
|
|
@@ -96,6 +99,7 @@ impl error::Error for Error { | |||||
| Error::InterfaceNotFound => None, | ||||||
| Error::Address(_) => None, | ||||||
| Error::InputOutput(e) => Some(e), | ||||||
| Error::InputOutputAddress(e, _) => Some(e), | ||||||
| Error::ExcessData => None, | ||||||
| Error::Handshake(_) => None, | ||||||
| Error::IncorrectEndian => None, | ||||||
|
|
@@ -125,6 +129,7 @@ impl fmt::Display for Error { | |||||
| Error::Address(e) => write!(f, "address error: {e}"), | ||||||
| Error::ExcessData => write!(f, "excess data"), | ||||||
| Error::InputOutput(e) => write!(f, "I/O error: {e}"), | ||||||
| Error::InputOutputAddress(e, address) => write!(f, "I/O error: {e} for {address}"), | ||||||
|
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. This will need to be update too:
Suggested change
|
||||||
| Error::Handshake(e) => write!(f, "D-Bus handshake failed: {e}"), | ||||||
| Error::IncorrectEndian => write!(f, "incorrect endian"), | ||||||
| Error::InvalidField => write!(f, "invalid message field"), | ||||||
|
|
@@ -160,6 +165,9 @@ impl Clone for Error { | |||||
| Error::Address(e) => Error::Address(e.clone()), | ||||||
| Error::ExcessData => Error::ExcessData, | ||||||
| Error::InputOutput(e) => Error::InputOutput(e.clone()), | ||||||
| Error::InputOutputAddress(e, address) => { | ||||||
| Error::InputOutputAddress(e.clone(), address.clone()) | ||||||
| } | ||||||
| Error::Handshake(e) => Error::Handshake(e.clone()), | ||||||
| Error::IncorrectEndian => Error::IncorrectEndian, | ||||||
| Error::InvalidField => Error::InvalidField, | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could have the
Address::connectdo the mapping instead, or returnResult<Stream, (io::Error, Self)(open to other options too) or maybe even have theAddress::connectjust not take ownership of address instance (it's internal after all).Since this should not require a major effort and there is no urgency here, I think it makes sense to already avoid the cloning here, instead of leaving it for the future, which is likely never going to happen. :)
P.S. do remember the atomic commits rule, so please put the needed refactoring in a separate commit that comes before this one. 🙏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just FYI, I would very much prefer the first option here: have the
Address::connect(orTransport::connect) do the mapping.