Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ All notable changes to this project will be documented in this file.

## [Unreleased]

## [0.14.1] - 2025-09-24

### Fixed
- Removed the unused `BacktraceSlot::get` helper to restore builds with `-D warnings`.
- Simplified the metrics recorder test harness with dedicated types to satisfy
`clippy::type_complexity` without sacrificing coverage.

## [0.14.0] - 2025-09-24

### Added
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "masterror"
version = "0.14.0"
version = "0.14.1"
rust-version = "1.90"
edition = "2024"
license = "MIT OR Apache-2.0"
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ guides, comparisons with `thiserror`/`anyhow`, and troubleshooting recipes.

~~~toml
[dependencies]
masterror = { version = "0.14.0", default-features = false }
masterror = { version = "0.14.1", default-features = false }
# or with features:
# masterror = { version = "0.14.0", features = [
# masterror = { version = "0.14.1", features = [
# "axum", "actix", "openapi", "serde_json",
# "tracing", "metrics", "backtrace", "sqlx",
# "sqlx-migrate", "reqwest", "redis", "validator",
Expand Down Expand Up @@ -77,10 +77,10 @@ masterror = { version = "0.14.0", default-features = false }
~~~toml
[dependencies]
# lean core
masterror = { version = "0.14.0", default-features = false }
masterror = { version = "0.14.1", default-features = false }

# with Axum/Actix + JSON + integrations
# masterror = { version = "0.14.0", features = [
# masterror = { version = "0.14.1", features = [
# "axum", "actix", "openapi", "serde_json",
# "tracing", "metrics", "backtrace", "sqlx",
# "sqlx-migrate", "reqwest", "redis", "validator",
Expand Down Expand Up @@ -714,13 +714,13 @@ assert_eq!(resp.status, 401);
Minimal core:

~~~toml
masterror = { version = "0.14.0", default-features = false }
masterror = { version = "0.14.1", default-features = false }
~~~

API (Axum + JSON + deps):

~~~toml
masterror = { version = "0.14.0", features = [
masterror = { version = "0.14.1", features = [
"axum", "serde_json", "openapi",
"sqlx", "reqwest", "redis", "validator", "config", "tokio"
] }
Expand All @@ -729,7 +729,7 @@ masterror = { version = "0.14.0", features = [
API (Actix + JSON + deps):

~~~toml
masterror = { version = "0.14.0", features = [
masterror = { version = "0.14.1", features = [
"actix", "serde_json", "openapi",
"sqlx", "reqwest", "redis", "validator", "config", "tokio"
] }
Expand Down
4 changes: 0 additions & 4 deletions src/app_error/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ impl BacktraceSlot {
*self = Self::with(backtrace);
}

fn get(&self) -> Option<&Backtrace> {
self.cell.get().and_then(|value| value.as_ref())
}

fn capture_if_absent(&self) -> Option<&Backtrace> {
self.cell
.get_or_init(|| Some(Backtrace::capture()))
Expand Down
39 changes: 27 additions & 12 deletions src/app_error/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,28 +313,44 @@ fn metrics_counter_is_incremented_once() {
Counter, CounterFn, Gauge, Histogram, Key, KeyName, Metadata, Recorder, SharedString, Unit
};

#[derive(Clone, Debug, Eq, PartialEq, Hash)]
struct CounterKey {
name: String,
labels: Vec<(String, String)>
}

impl CounterKey {
fn new(name: String, labels: Vec<(String, String)>) -> Self {
Self {
name,
labels
}
}
}

type CounterMap = HashMap<CounterKey, u64>;
type SharedCounterMap = Arc<Mutex<CounterMap>>;

#[derive(Clone)]
struct MetricsCounterHandle {
name: String,
labels: Vec<(String, String)>,
counts: Arc<Mutex<HashMap<(String, Vec<(String, String)>), u64>>>
key: CounterKey,
counts: SharedCounterMap
}

impl CounterFn for MetricsCounterHandle {
fn increment(&self, value: u64) {
let mut map = self.counts.lock().expect("counter map");
*map.entry((self.name.clone(), self.labels.clone()))
.or_default() += value;
*map.entry(self.key.clone()).or_default() += value;
}

fn absolute(&self, value: u64) {
let mut map = self.counts.lock().expect("counter map");
map.insert((self.name.clone(), self.labels.clone()), value);
map.insert(self.key.clone(), value);
}
}

struct CountingRecorder {
counts: Arc<Mutex<HashMap<(String, Vec<(String, String)>), u64>>>
counts: SharedCounterMap
}

impl Recorder for CountingRecorder {
Expand All @@ -361,9 +377,9 @@ fn metrics_counter_is_incremented_once() {
.labels()
.map(|label| (label.key().to_owned(), label.value().to_owned()))
.collect::<Vec<_>>();
let counter_key = CounterKey::new(key.name().to_owned(), labels);
Counter::from_arc(Arc::new(MetricsCounterHandle {
name: key.name().to_owned(),
labels,
key: counter_key,
counts: self.counts.clone()
}))
}
Expand All @@ -379,8 +395,7 @@ fn metrics_counter_is_incremented_once() {

use std::sync::OnceLock;

static RECORDER_COUNTS: OnceLock<Arc<Mutex<HashMap<(String, Vec<(String, String)>), u64>>>> =
OnceLock::new();
static RECORDER_COUNTS: OnceLock<SharedCounterMap> = OnceLock::new();

let counts = RECORDER_COUNTS
.get_or_init(|| {
Expand All @@ -398,7 +413,7 @@ fn metrics_counter_is_incremented_once() {
let err = AppError::forbidden("denied");
err.log();

let key = (
let key = CounterKey::new(
"error_total".to_owned(),
vec![
("code".to_owned(), AppCode::Forbidden.as_str().to_owned()),
Expand Down
Loading