Replace anyhow with miette #15
Labels
No labels
wayfinder
grilling
wayfinder
map
wayfinder
prototype
wayfinder
research
wayfinder
task
workflow
needs-info
workflow
needs-triage
workflow
ready-for-agent
workflow
ready-for-human
workflow
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
rosa/tomate#15
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
I like
miettea lot. With thefancyfeature.Agent Brief
Category: enhancement
Summary: Replace
anyhowwithmiette, giving each library module a concrete diagnostic error type with codes, help text, and a source span on the duration parserCurrent behavior:
Every fallible path in the crate returns
anyhow::Result. Errors are built twoways:
with_contextwrapping an underlying failure (about 29 sites) andanyhow!/bail!raising a bare message (about 7 sites). All of them carry astring and nothing else — no machine-readable code, no suggested next step, and
no pointer into the input that caused the failure.
Three consequences:
anyhow::Resultappears in the public signatures of the library crate(status loading, config loading and saving, history loading and appending,
the session lifecycle functions). Callers of
tomateas a library get anerased error type with no variants to match on.
mainreturnsanyhow::Result, so a failure prints a plainmessage chain.
which is why
anyhowis also listed under[build-dependencies].Desired behavior:
The crate uses
miette(with thefancyfeature) as its diagnostic layer, andeach library module defines its own concrete error type instead of an erased
one.
thiserror::Errorandmiette::Diagnostic. Variants are named for thefailure, not for the operation that hit it.
tomate::<module>::<variant>.#[help]namingthe command that resolves it. At minimum: starting a session while a break is
running, starting a break while a session is running, acting on a session
when none is active, and an unparseable duration string.
execution, timer scheduling) keep that failure as
#[source]so the chainstill renders.
#[source_code]and a#[label]span, so an unparseable duration renderswith the offending text underlined.
miette::Resultfrommain, so thefancyreporterrenders every failure.
Key interfaces:
anyhow::Result<T>returnResult<T, <Module>Error>with a concrete type. This is a breaking change tothe library API and is intended.
miette::Reportat the call site; itdoes not define its own catch-all error enum.
library/binary and once into the build script. Whatever error type it returns
must be available in both. Either add
miette/thiserrorto[build-dependencies]alongside the existing entries, or give the parser anerror type that does not depend on the diagnostic crates. Either is
acceptable; the build must succeed.
anyhowis removed from[dependencies]and[build-dependencies].Acceptance criteria:
anyhowentry remains inCargo.tomlunder any dependency table, andno
use anyhoworanyhow::reference remains in the source.mietteis a dependency with thefancyfeature enabled.type; no erased or boxed error type appears in the public API.
codefollowingtomate::<module>::<variant>.tomate pomodoro startwhile a break is running, andtomate pomodoro stopwith no session active, each print help textnaming the command to run instead.
tomate pomodoro start --duration 25xrenders a diagnostic thatunderlines the offending input rather than printing a bare message.
in the rendered output.
mise run cipasses — this coverscargo check,cargo audit,cargo clippy -- -D warnings,cargo doc,cargo fmt --check, andcargo test --all-targets. The build script must build.CHANGELOG.mdgains an entry under[Unreleased]marked**BREAKING**,describing the public error type change in the same style as the 0.5.0
entry.
Out of scope:
Cargo.toml.cargo-releaseowns that; only thechangelog entry is written by hand.
labels. If a message is wrong, note it rather than rewriting it.
failure cases.
human_panic. The panic handler stays as it is.tracingsetup or any logging output.crate-wide enum.
Open decision flagged during triage: the brief assumes one error enum per
module rather than a single crate-wide enum. That matches the existing module
layout and keeps each module's failure surface local. If a crate-wide enum is
preferred, say so before starting — it changes the shape of most of the diff.