Repository navigation
fix: propagate formatting errors in PlainTextLayout and TextLayout - #310
Merged
Merged
Conversation
`PlainTextLayout` and `TextLayout` previously wrote into `Vec<u8>` via `std::io::Write::write_fmt` with `.unwrap()`, causing `std::io` to panic on the caller thread whenever a payload or structured value `Display` or `Debug` implementation returned `Err(fmt::Error)`, and leaving partial bytes in `buf` when visiting key-values or diagnostics failed. Format record segments through `std::fmt::Write`, capture `buf`'s starting length, truncate partial output on any timestamp, formatting, or visitor error, and return `Err(Error)` with the underlying cause so the pipeline forwards failures to `ErrorSink` without panicking. Signed-off-by: tison <[email protected]>
Signed-off-by: tison <[email protected]>
Replace the inline closures in `PlainTextLayout::format` and `TextLayout::format` with `do_format` methods, free error helper functions, and `kv::Visitor` on `FmtBuf` so error propagation and buffer rollback read top-to-bottom without nested closure indentation. Signed-off-by: tison <[email protected]>
Signed-off-by: tison <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Propagate
fmt::Errorand roll back partial buffer writes inPlainTextLayoutandTextLayoutinstead of panicking on the caller thread.Previously, writing into
buf: &mut Vec<u8>throughstd::io::Write::write_fmtand.unwrap()panicked insidestd::io::default_write_fmtwhenever a userDisplayorDebugimplementation returnedErr(fmt::Error), and visitor errors left partially formatted bytes appended tobuf.Changes
logforth-core(PlainTextLayout) &logforth-layout-text(TextLayout):std::fmt::Writeadapter overVec<u8>(and propagatejifftimestamp printing errors inTextLayout) asErrorvalues preserving.source().buf.len()up front and truncatebufback to its starting length on any formatting or key-value/diagnostic visitor error.# Errorscontracts onPlainTextLayoutandTextLayout, and updateCHANGELOG.md.FailingDisplaypayload and key-value tests alongsideFailingDiagrollback assertions for bothPlainTextLayoutandTextLayout, verifying untouched caller buffers and end-to-end routing toErrorSink.