Repository navigation
Conversation
`logforth-core` previously depended on `anyhow` solely for `Error::with_source`, leaking `anyhow::Error` into its public signature while returning an unboxed 56-byte `Error` struct across hot `Visitor::visit` and `Append::append` paths. Box the internal error representation into a pointer-sized payload carrying a `Cow<'static, str>` message and an optional `Box<dyn std::error::Error + Send + Sync + 'static>` cause: - Drop the mandatory `anyhow` dependency from `logforth-core` while preserving `Into` compatibility for standard errors, strings, and boxed causes. - Shrink `Result<(), Error>` to a single word on the stack, add `Error::message()`, walk the full `.source()` chain in `Debug`, and allow `with_source` to replace causes without panicking. - Remove unused `with_context`, `sources`, `from_io_error`, and `from_fmt_error` helpers, replacing generic I/O wrappers with descriptive operation messages at each appender call site. - Expose `logforth_core::error` and `logforth::error` modules directly. Signed-off-by: tison <wander4096@gmail.com>
Runtime pipeline failures previously followed three disconnected paths: `Logger` wrote multi-line dumps directly to standard error and panicked if standard error was unavailable, `Async` forwarded worker failures to `Trap`, and `File` mixed `Result` returns with a separate `FileBuilder::trap` for rollover housekeeping and `Drop`. In addition, requiring `fmt::Debug` on `Trap` prevented passing closures directly. Unify internal runtime error handling around a cloneable `error::ErrorSink` value: - Replace `trap::Trap` and `BestEffortTrap` with `error::ErrorSink` providing `ErrorSink::stderr()` (default, best-effort without panicking), `ErrorSink::black_hole()`, and `ErrorSink::new(...)` / closure `From` conversions. - Wire `.error_sink(...)` into `LoggerBuilder`, `LogStarterBuilder`, `LogStarterStdStreamBuilder`, `LogStarterTestingBuilder`, and `AsyncBuilder`, removing the hardcoded standard-error panic path in `Logger`. - Remove `FileBuilder::trap` and `RollingFileWriter`'s `Drop` callback; when log rotation or archive cleanup fails, finish writing the current record to the active file and return the rollover error through `Append::append` to the owning execution root. Signed-off-by: tison <wander4096@gmail.com>
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.
Problem
logforth-coredepended onanyhowsolely forError::with_source, leakinganyhow::Errorinto its public signature while returning an unboxed 56-byteErrorstruct by value acrossVisitor::visit,Diagnostic::visit,Layout::format, andAppend::append.LoggerbypassedTrap, wrote multi-line dumps directly to standard error, and panicked if standard error was unavailable.Asyncforwarded worker errors toTrap, whosefmt::Debugsupertrait prevented passing closures directly.FilereturnedResultfor writes and flushes while routing rollover housekeeping andDropflush errors to a separateFileBuilder::trap.Solution
Error:Error's payload (Cow<'static, str>message + optionalBox<dyn std::error::Error + Send + Sync + 'static>source) sologforth-corehas zero mandatory dependencies andResult<(), Error>fits in a single word (8bytes on 64-bit targets).Error::message(), walk the full.source()chain inDebug, allowwith_sourceto replace an existing cause without panicking, and remove unusedwith_context,sources,from_io_error, andfrom_fmt_errorhelpers in favor of descriptive operation messages at each call site.error::ErrorSinkat execution roots:trap::TrapandBestEffortTrapwith a cloneableerror::ErrorSinkvalue supportingErrorSink::stderr()(default, best-effort without panicking),ErrorSink::black_hole(), andErrorSink::new(...)/ closureFromconversions..error_sink(...)intoLoggerBuilder,LogStarterBuilder,LogStarterStdStreamBuilder,LogStarterTestingBuilder, andAsyncBuilder, removing the hardcoded standard-error panic path inLogger.FileBuilder::trap; when log rotation or archive cleanup fails,RollingFileWriterstill writes the current record to the active file and returns the rollover error throughAppend::appendto the owning execution root.Validation
cargo x testcargo x lintRUSTDOCFLAGS="-D warnings" cargo doc --no-deps --workspace --all-featurescargo +1.91.0 test -p logforth-corecargo tree -p logforth-core --edges normal(zero dependencies)