Skip to content

Re-export SerDeError since it should be part of the API#438

Merged
sagudev merged 1 commit intoservo:mainfrom
glyn:reexport-SerDeError
Jan 20, 2026
Merged

Re-export SerDeError since it should be part of the API#438
sagudev merged 1 commit intoservo:mainfrom
glyn:reexport-SerDeError

Conversation

@glyn
Copy link
Contributor

@glyn glyn commented Jan 19, 2026

Also display the detail of a SerDeError.

@Narfinger: please review.

mod test;

pub use error::{IpcError, TryRecvError, TrySelectError};
pub use error::{IpcError, SerDeError, TryRecvError, TrySelectError};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been mulling this change over and there is a trade-off between strict API compatibility and usefulness of diagnostics. The change:

  • Would cause API compatibility to be broken if Postcard is replaced by another serialisation mechanism in the future or if postcard::Error changes incompatibly in the future.
  • Enables callers (i.e. other crates) to distinguish programmatically between various instances of IpcError::SerializationError (I added a test to cover this).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should have exported this never the less.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually given that this type is already used in public API it is surprising there is no rust/clippy warning.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed.

@glyn glyn changed the title Re-export SerDeError since it is part of the API Re-export SerDeError since it should be part of the API Jan 20, 2026
Copy link
Member

@sagudev sagudev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should export SerDeError, but as opaque error type, so on cannot really inspect inner error (we do not want postcard to be in out API) at least programmatically. For developers there is still Debug and Display which I think should be enough.

src/error.rs Outdated
Comment on lines 46 to 68
#[cfg(test)]
mod tests {
use super::*;

#[test]
fn distinguish_between_serialization_errors() {
let err = IpcError::SerializationError(SerDeError(postcard::Error::DeserializeBadBool));
if let IpcError::SerializationError(ser_de_err) = err {
assert_eq!(ser_de_err.0, postcard::Error::DeserializeBadBool);
} else {
panic!("Unexpected enum variant")
}
}

#[test]
fn display_ser_de_error() {
let ser_de_error = SerDeError(postcard::Error::DeserializeBadBool);
assert_eq!(
format!("{}", ser_de_error),
"Serialization/Deserialization: Found a bool that wasn't 0 or 1"
);
}
}
Copy link
Member

@sagudev sagudev Jan 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the only reason why distinguish_between_serialization_errors works is because these are unit tests, thus they live in same crate, thus they can inspect inner of pub struct SerDeError(#[from] pub(crate) postcard::Error);, but they should not work as integration tests because one cannot access inner content.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct - I tried it and it didn't work.

mod test;

pub use error::{IpcError, TryRecvError, TrySelectError};
pub use error::{IpcError, SerDeError, TryRecvError, TrySelectError};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should have exported this never the less.

@glyn glyn force-pushed the reexport-SerDeError branch from 5259374 to f5502ea Compare January 20, 2026 08:47
@Narfinger
Copy link
Contributor

I agree with sagudev that the error can be exposes as long as we do not expose the inner error so we can easily change it without breaking api compatibility.

@glyn
Copy link
Contributor Author

glyn commented Jan 20, 2026

@sagudev @Narfinger I agree with your reasoning, so I've cut this PR back to the initial commit - the re-export of SerDeError.

@sagudev sagudev added this pull request to the merge queue Jan 20, 2026
Merged via the queue into servo:main with commit 3aa8068 Jan 20, 2026
73 of 75 checks passed
@glyn glyn deleted the reexport-SerDeError branch January 20, 2026 10:33
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.

3 participants