Skip to content

RUST-1406 Convert serde errors to standard error type #562

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

isabelatkinson
Copy link
Contributor

@isabelatkinson isabelatkinson commented Jun 27, 2025

This is the last of the conversions.

Self::DeserializationError {
message: err.to_string(),
}
fn from(error: serde_json::Error) -> Self {
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 kept this From impl in the public API because we're already exposing a bunch of serde_json conversions below. It might be worth putting all of the serde_json stuff behind the serde feature flag or giving it its own flag - if that makes sense I'll file a separate ticket.

fn serialize_bool(self, v: bool) -> Result<Self::Ok> {
Err(Self::invalid_key(v))
fn serialize_bool(self, _v: bool) -> Result<Self::Ok> {
Err(Error::invalid_key_type("bool"))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a deviation from the current API, which stores the invalid key as Bson. This leads to some weird placeholders (empty arrays and documents, Bson::Null if conversion fails). I think a string message that reports the bad type is sufficient here, and users can turn on serde_path_to_error for more detail.

@isabelatkinson isabelatkinson marked this pull request as ready for review June 27, 2025 17:18
@isabelatkinson isabelatkinson requested a review from a team as a code owner June 27, 2025 17:18
@isabelatkinson isabelatkinson requested a review from abr-egn June 27, 2025 17:18
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.

1 participant