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
34 changes: 34 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,40 @@ All notable changes to this project will be documented in this file.

## [Unreleased]

## [0.11.0] - 2025-10-26

### Changed
- Updated `AppError::database` to accept `Option<Cow<'static, str>>`, allowing
bare `None` calls without type annotations, and added the helper
`AppError::database_with_message` for the common message-bearing path.

### Documentation
- Refreshed the `AppError::database` docs to illustrate the new constructor
behavior and helper usage.

### Tests
- Expanded database constructor tests to cover both the helper and bare `None`
scenario.

## [0.10.9] - 2025-10-26

### Fixed
- Tightened Turnkey rate-limit heuristics to require explicit phrases while
preserving stack-backed searches for short ASCII patterns, preventing matches
on unrelated words such as "corporate".

### Tests
- Added regression coverage to ensure corporate network outages and operational
failure rates classify as network/service issues rather than rate limits.

### Changed
- Raised the documented MSRV to Rust 1.90 to match the `rust-version`
requirement.

### Documentation
- Regenerated the README from the template so installation snippets reflect the
new crate version and MSRV statement.

## [0.10.8] - 2025-10-25

### Fixed
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.10.8"
version = "0.11.0"
rust-version = "1.90"
edition = "2024"
license = "MIT OR Apache-2.0"
Expand Down
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ Stable categories, conservative HTTP mapping, no `unsafe`.

~~~toml
[dependencies]
masterror = { version = "0.10.8", default-features = false }
masterror = { version = "0.11.0", default-features = false }
# or with features:
# masterror = { version = "0.10.8", features = [
# masterror = { version = "0.11.0", features = [
# "axum", "actix", "openapi", "serde_json",
# "sqlx", "sqlx-migrate", "reqwest", "redis",
# "validator", "config", "tokio", "multipart",
Expand Down Expand Up @@ -66,10 +66,11 @@ masterror = { version = "0.10.8", default-features = false }
~~~toml
[dependencies]
# lean core
masterror = { version = "0.10.8", default-features = false }
masterror = { version = "0.11.0", default-features = false }

# with Axum/Actix + JSON + integrations
# masterror = { version = "0.10.8", features = [
# masterror = { version = "0.11.0", features = [

# "axum", "actix", "openapi", "serde_json",
# "sqlx", "sqlx-migrate", "reqwest", "redis",
# "validator", "config", "tokio", "multipart",
Expand Down Expand Up @@ -378,7 +379,7 @@ diagnostics.

| Specifier | `core::fmt` trait | Example output | Notes |
|------------------|----------------------------|------------------------|-------|
| _default_ | `core::fmt::Display` | `value` | User-facing strings; `#` has no effect. |
| *default* | `core::fmt::Display` | `value` | User-facing strings; `#` has no effect. |
| `:?` / `:#?` | `core::fmt::Debug` | `Struct { .. }` / multi-line | Mirrors `Debug`; `#` pretty-prints structs. |
| `:x` / `:#x` | `core::fmt::LowerHex` | `0x2a` | Hexadecimal; `#` prepends `0x`. |
| `:X` / `:#X` | `core::fmt::UpperHex` | `0x2A` | Uppercase hex; `#` prepends `0x`. |
Expand Down Expand Up @@ -578,6 +579,8 @@ assert_eq!(resp.status, 401);

</details>

</details>

<details>
<summary><b>Feature flags</b></summary>

Expand Down Expand Up @@ -623,13 +626,13 @@ assert_eq!(resp.status, 401);
Minimal core:

~~~toml
masterror = { version = "0.10.8", default-features = false }
masterror = { version = "0.11.0", default-features = false }
~~~

API (Axum + JSON + deps):

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

~~~toml
masterror = { version = "0.10.8", features = [
masterror = { version = "0.11.0", features = [
"actix", "serde_json", "openapi",
"sqlx", "reqwest", "redis", "validator", "config", "tokio"
] }
Expand Down Expand Up @@ -709,4 +712,3 @@ MSRV = 1.90 (may raise in minor, never in patch).
Apache-2.0 OR MIT, at your option.

</details>

2 changes: 2 additions & 0 deletions README.template.md
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,8 @@ assert_eq!(resp.status, 401);

</details>

</details>

<details>
<summary><b>Feature flags</b></summary>

Expand Down
31 changes: 27 additions & 4 deletions src/app_error/constructors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,39 @@ impl AppError {
}
/// Build a `Database` error with an optional message.
///
/// Accepts `Option` to avoid gratuitous `.map(|...| ...)` at call sites
/// when you may or may not have a safe-to-print string at hand.
pub fn database(msg: Option<impl Into<Cow<'static, str>>>) -> Self {
/// This constructor accepts a pre-built [`Cow`] so callers that already
/// manage ownership can pass either borrowed or owned strings. When you
/// have plain string data, prefer [`AppError::database_with_message`].
///
/// ```rust
/// use masterror::AppError;
///
/// let err = AppError::database(None);
/// assert!(err.message.is_none());
/// ```
pub fn database(msg: Option<Cow<'static, str>>) -> Self {
Self {
kind: AppErrorKind::Database,
message: msg.map(Into::into),
message: msg,
retry: None,
www_authenticate: None
}
}

/// Build a `Database` error with a message.
///
/// Convenience wrapper around [`AppError::database`] for the common case
/// where you start from a plain string-like value.
///
/// ```rust
/// use masterror::AppError;
///
/// let err = AppError::database_with_message("db down");
/// assert_eq!(err.message.as_deref(), Some("db down"));
/// ```
pub fn database_with_message(msg: impl Into<Cow<'static, str>>) -> Self {
Self::database(Some(msg.into()))
}
/// Build a `Config` error.
pub fn config(msg: impl Into<Cow<'static, str>>) -> Self {
Self::with(AppErrorKind::Config, msg)
Expand Down
9 changes: 7 additions & 2 deletions src/app_error/tests.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::borrow::Cow;

use super::{AppResult, core::AppError};
use crate::AppErrorKind;

Expand Down Expand Up @@ -108,10 +110,13 @@ fn constructors_match_kinds() {

#[test]
fn database_accepts_optional_message() {
let with_msg = AppError::database(Some("db down"));
let with_msg = AppError::database_with_message("db down");
assert_err_with_msg(with_msg, AppErrorKind::Database, "db down");

let without = AppError::database(None::<&str>);
let via_option = AppError::database(Some(Cow::Borrowed("db down")));
assert_err_with_msg(via_option, AppErrorKind::Database, "db down");

let without = AppError::database(None);
assert_err_bare(without, AppErrorKind::Database);
}

Expand Down
4 changes: 2 additions & 2 deletions src/convert/sqlx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl From<SqlxError> for AppError {
fn from(err: SqlxError) -> Self {
match err {
SqlxError::RowNotFound => AppError::not_found("Record not found"),
other => AppError::database(Some(other.to_string()))
other => AppError::database_with_message(other.to_string())
}
}
}
Expand All @@ -63,7 +63,7 @@ impl From<SqlxError> for AppError {
#[cfg_attr(docsrs, doc(cfg(feature = "sqlx-migrate")))]
impl From<MigrateError> for AppError {
fn from(err: MigrateError) -> Self {
AppError::database(Some(err.to_string()))
AppError::database_with_message(err.to_string())
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
//!
//! # Minimum Supported Rust Version (MSRV)
//!
//! MSRV is **1.89**. New minor releases may increase MSRV with a changelog
//! MSRV is **1.90**. New minor releases may increase MSRV with a changelog
//! note, but never in a patch release.
//!
//! # Feature flags
Expand Down
Loading
Loading