Skip to content

refactor!: redesign Error without anyhow dependency - #248

Merged
tisonkun merged 1 commit into
mainfrom
refactor/core-error
Nov 25, 2026
Merged

tisonkun merged 1 commit into
mainfrom
refactor/core-error

Conversation

@tisonkun

Copy link
Copy Markdown
Contributor

Summary

logforth-core previously depended on anyhow solely for Error::with_source, coupling logforth-core's public API to anyhow while returning an unboxed 56-byte Error struct across hot Visitor::visit, Layout::format, and Append::append return paths.

This change boxes the internal error representation (ErrorState) into a pointer-sized payload carrying a Cow<'static, str> message and an optional Box<dyn std::error::Error + Send + Sync + 'static> cause, aligning logforth_core::Error with DESIGN.md:

  • Remove the mandatory anyhow dependency from Cargo.toml and logforth-core, leaving logforth-core with zero mandatory third-party dependencies.
  • Shrink Error and Result<(), Error> to a single machine word (8 bytes on 64-bit targets).
  • Add Error::message(), walk the full .source() chain in Debug output, and allow Error::with_source to replace an existing cause without panicking.
  • Remove with_context, sources, from_io_error, and from_fmt_error, replacing generic "failed to perform io" wrappers with operation-specific messages at each appender call site.

`logforth-core` previously depended on `anyhow` solely for `Error::with_source`, coupling `logforth-core`'s public error signature to `anyhow` while returning an unboxed 56-byte `Error` struct across hot `Visitor::visit`, `Layout::format`, and `Append::append` paths.

Box the internal error state (`ErrorState`) into a pointer-sized payload carrying a `Cow<'static, str>` message and an optional `Box<dyn std::error::Error + Send + Sync + 'static>` cause:
- Remove the mandatory `anyhow` dependency from `logforth-core` while preserving `Into` conversions for standard errors, strings, and boxed causes.
- Shrink `Result<(), Error>` to a single word on the stack, expose `Error::message()`, walk the full `.source()` chain in `Debug`, and allow `with_source` to replace an existing cause without panicking.
- Remove `with_context`, `sources`, `from_io_error`, and `from_fmt_error`, replacing generic I/O wrappers with descriptive operation messages at each appender call site.

Signed-off-by: tison <wander4096@gmail.com>
@tisonkun
tisonkun merged commit f7dde0b into main Nov 25, 2026
10 checks passed
@tisonkun
tisonkun deleted the refactor/core-error branch November 25, 2026 03:59
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