Skip to content

Errors & features

Result and KobanError

Library functions return koban::Result<T>, an alias for std::result::Result<T, KobanError>. KobanError is a thiserror enum with one variant per failure mode:

VariantWhen it occurs
MissingTokenINVOICE_NINJA_API_TOKEN is not configured.
InvalidBaseUrlThe base URL could not be parsed.
InsecureBaseUrlThe base URL is not HTTPS (and is not a local host).
InvalidEndpointAn API URL could not be built for a path.
TransportThe request could not reach Invoice Ninja.
ApiInvoice Ninja returned a non-success HTTP status.
DecodeA response could not be decoded into the expected shape.
InvalidFilterA list filter value was rejected.
InvalidPayloadA write payload failed validation.
ConfirmationRequiredA guarded operation needs explicit confirmation.
FileA download file could not be written.
UpdateA self-update step failed.

Tokens are never embedded in error messages — the redact helper is used to strip them from any text that might contain one.

rust
use koban::{ApiClient, Config, KobanError};

match ApiClient::new(Config::from_env()?).invoices().list().await {
    Ok(invoices) => println!("{} invoices", invoices.len()),
    Err(KobanError::Api { status, .. }) => eprintln!("API error: HTTP {status}"),
    Err(err) => eprintln!("{err}"),
}

The miette feature

By default the library depends only on thiserror. Enable the optional miette feature to derive miette::Diagnostic on KobanError, adding diagnostic help text suitable for rich CLI error reporting:

toml
[dependencies]
koban = { version = "0.1", features = ["miette"] }

The koban-cli crate enables this feature; most library consumers can leave it off and keep the dependency tree lean.

redact

koban::redact(text, token) returns a copy of text with token replaced by a redaction marker. koban uses it internally so tokens never leak into errors, traces, or logs; it is re-exported so you can apply the same guarantee to your own logging.

Released under the MIT License.