Skip to content
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

defmt-print: Recover from decoding-errors #598

Merged
merged 11 commits into from
Oct 1, 2021
Merged

defmt-print: Recover from decoding-errors #598

merged 11 commits into from
Oct 1, 2021

Conversation

Urhengulas
Copy link
Member

This PR uses the new StreamDecoder-API in defmt-print and utilizes it to recover from decoding errors.

Fixes #559

Copy link
Member

@japaric japaric left a comment

Choose a reason for hiding this comment

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

changes look good. left some suggestions

Encoding::Raw => return Err(DecodeError::Malformed.into()),
// rzcobs encoding allows recovery from decoding-errors. therefore we stop
// decoding the current, corrupted, data and continue with new one
Encoding::Rzcobs => break,
Copy link
Member

@japaric japaric Oct 1, 2021

Choose a reason for hiding this comment

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

I think this should be continue because may be more data cached in the stream_decoder. if there isn't an entire frame then the next iteration will hit the Eof case (which will make the program fetch more data from stdin)

Copy link
Member Author

Choose a reason for hiding this comment

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

👍🏾

match stream_decoder.decode() {
Ok(frame) => forward_to_logger(&frame, location_info(&locs, &frame, &current_dir)),
Err(DecodeError::UnexpectedEof) => break,
Err(DecodeError::Malformed) => match table.encoding() {
Copy link
Member

Choose a reason for hiding this comment

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

could you move the 'can this encoding recover?' logic into a method on the Encoding enum itself? I think consumers should not be deciding on the Encoding variant but rather the defmt-decoder library should provide them that information.

Copy link
Member Author

Choose a reason for hiding this comment

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

👍🏾

decoder/src/lib.rs Show resolved Hide resolved
Copy link
Member

@japaric japaric left a comment

Choose a reason for hiding this comment

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

👍 Thanks! Feel free to send to bors with nits addressed or unaddressed

decoder/src/lib.rs Outdated Show resolved Hide resolved
match stream_decoder.decode() {
Ok(frame) => forward_to_logger(&frame, location_info(&locs, &frame, &current_dir)),
Err(DecodeError::UnexpectedEof) => break,
Err(DecodeError::Malformed) => match table.encoding().recoverable() {
Copy link
Member

Choose a reason for hiding this comment

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

(probably down to personal preference but if boolean is more common than match boolean IMO)

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it is more common to use if. But match saves one line 😋

print/src/main.rs Outdated Show resolved Hide resolved
@Urhengulas
Copy link
Member Author

bors r+

bors bot added a commit that referenced this pull request Oct 1, 2021
598: `defmt-print`: Recover from decoding-errors r=Urhengulas a=Urhengulas

This PR uses the new `StreamDecoder`-API in `defmt-print` and utilizes it to recover from decoding errors.

Fixes #559 

Co-authored-by: Johann Hemmann <johann.hemmann@code.berlin>
@bors
Copy link
Contributor

bors bot commented Oct 1, 2021

Build failed:

@Urhengulas
Copy link
Member Author

bors retry

@bors
Copy link
Contributor

bors bot commented Oct 1, 2021

Build succeeded:

@bors bors bot merged commit b3cfde5 into main Oct 1, 2021
@bors bors bot deleted the recover branch October 1, 2021 20:46
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.

defmt-print cannot recover from decoding errors
2 participants