-
Notifications
You must be signed in to change notification settings - Fork 83
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
Stop using #[serde(untagged)]
for Message enum
#206
Conversation
src/conn.rs
Outdated
Ok(msg) | ||
} | ||
Err(err) => { | ||
tracing::debug!(target: "chromiumoxide::conn::raw_ws::parse_errors", msg = text, "Failed to parse raw WS message"); |
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.
tracing::debug!(target: "chromiumoxide::conn::raw_ws::parse_errors", msg = text, "Failed to parse raw WS message"); | |
tracing::trace!(target: "chromiumoxide::conn::raw_ws::parse_errors", msg = text, "Failed to parse raw WS message"); |
This can potentially be a large steam of data, let's downgrade the log level here?
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.
Looks great!
Why not implement a custom serde deserializer instead? It would be more idiomatic than going through a I would maybe throw the first error that is recorded. If we hit an "invalid" Response, it would be nicer to have a serde error of it instead of the a generic error because it tried to deserialize a Response into an Event (but that would mean an "invalid" event would get a generic error, so not super either). Something like: let mut error = None;
match serde_json::from_str::<Response>(s) {
Ok(v) => return Ok(v),
Err(e) => { error = Some(e); }
}
match serde_json::from_str::<Event>(s) {
Ok(v) => Ok(v),
Err(e) => Err(error.unwrap_or(e))
} |
As the mention on the issue, I should provide a test data that emits error without this changes and ok with this change. |
I see this state as the result of the following potential process:
So, it looks fine to me, although some additional TODOs and comments explaining this design might be useful. The proper implementation, in my view, should use the deserializer, because then it is simply a lower level compared to the |
I've marked this as non-draft since the base change is merged now. I've tried to reproduce #167 (comment) but failed, and I've not found any specific test case that ensures that this change fixes it yet.
I forgot to answer that.
I prefer the 3 of always returning the Event error, as I suppose it never fails to parse a JSON that is sent from Chromium and intended as a response, not an event, that means I can approximate "failure on parsing a Message equals to failure on parsing an Event". The reasoning is that the schema of The main branch is almost the same as the 4, so it should return a more detailed error after this was merged. |
I've implemented |
This is not needed, I did some tests. Please close @mattsse |
This is a draft because this uses not merged change from #204, which parses only textual message.it's merged and now this is ready for reviewsRelated to:
#[serde(untagged)]
does not work correctly with serde_json and some numeric types in the schema, without activating thearbitrary_precision
feature of serde_json and usingserde_json::Number
instead of all usage off64
or else.In this change, I replaced the derived
Deserialize
with an implementation ofFromStr
by usingserde_json
in it.Also, with this change, the error message will be more detailed compared to just "did not match any variant of untagged enum". Currently, it reports an error only about
T
forMessage::Event
.