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

## [Unreleased]

## [0.24.4] - 2025-10-20

### Fixed
- Implemented a manual OpenAPI schema for `AppCode`, restoring `utoipa`
compatibility and documenting the SCREAMING_SNAKE_CASE contract in generated
specs.
- Emitted owned label values when incrementing `error_total` telemetry metrics
so the updated `metrics` crate no longer requires `'static` lifetimes.
- Relaxed gRPC metadata serialization to avoid `'static` lifetime requirements
introduced by recent compiler changes, preserving zero-copy formatting where
possible.

## [0.24.3] - 2025-10-19

### 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.24.3"
version = "0.24.4"
rust-version = "1.90"
edition = "2024"
license = "MIT OR Apache-2.0"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ The build script keeps the full feature snippet below in sync with

~~~toml
[dependencies]
masterror = { version = "0.24.3", default-features = false }
masterror = { version = "0.24.4", default-features = false }
# or with features:
# masterror = { version = "0.24.3", features = [
# masterror = { version = "0.24.4", features = [
# "std", "axum", "actix", "openapi",
# "serde_json", "tracing", "metrics", "backtrace",
# "sqlx", "sqlx-migrate", "reqwest", "redis",
Expand Down
6 changes: 4 additions & 2 deletions src/app_error/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,10 +311,12 @@ impl Error {

#[cfg(feature = "metrics")]
{
let code_label = self.code.as_str().to_owned();
let category_label = kind_label(self.kind).to_owned();
metrics::counter!(
"error_total",
"code" => self.code.as_str(),
"category" => kind_label(self.kind)
"code" => code_label,
"category" => category_label
)
.increment(1);
}
Expand Down
23 changes: 21 additions & 2 deletions src/code/app_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ use core::{

use serde::{Deserialize, Deserializer, Serialize, Serializer};
#[cfg(feature = "openapi")]
use utoipa::ToSchema;
use utoipa::{
PartialSchema, ToSchema,
openapi::schema::{ObjectBuilder, Type}
};

use crate::kind::AppErrorKind;

Expand Down Expand Up @@ -40,7 +43,6 @@ impl CoreError for ParseAppCodeError {}
/// - Do not encode private/internal details in codes.
/// - Validate custom codes using [`AppCode::try_new`] before exposing them
/// publicly.
#[cfg_attr(feature = "openapi", derive(ToSchema))]
#[non_exhaustive]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct AppCode {
Expand Down Expand Up @@ -295,6 +297,23 @@ impl<'de> Deserialize<'de> for AppCode {
}
}

#[cfg(feature = "openapi")]
impl PartialSchema for AppCode {
fn schema() -> utoipa::openapi::RefOr<utoipa::openapi::schema::Schema> {
ObjectBuilder::new()
.schema_type(Type::String)
.description(Some(
"Stable machine-readable error code in SCREAMING_SNAKE_CASE.".to_owned()
))
.pattern(Some("^[A-Z0-9_]+$".to_owned()))
.build()
.into()
}
}

#[cfg(feature = "openapi")]
impl ToSchema for AppCode {}

fn validate_code(value: &str) -> Result<(), ParseAppCodeError> {
if !is_valid_literal(value) {
return Err(ParseAppCodeError);
Expand Down
12 changes: 10 additions & 2 deletions src/convert/tonic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ enum MetadataAscii<'a> {
impl AsRef<str> for MetadataAscii<'_> {
fn as_ref(&self) -> &str {
match self {
Self::Static(text) | Self::Buffer(text) => text,
Self::Static(text) => text,
Self::Buffer(text) => text,
Self::Owned(text) => text.as_str()
}
}
Expand Down Expand Up @@ -175,7 +176,14 @@ fn metadata_value_to_ascii<'a>(
match value {
FieldValue::Str(value) => {
let text = value.as_ref();
is_ascii_metadata_value(text).then_some(MetadataAscii::Static(text))
if !is_ascii_metadata_value(text) {
return None;
}

match value {
Cow::Borrowed(borrowed) => Some(MetadataAscii::Static(borrowed)),
Cow::Owned(owned) => Some(MetadataAscii::Owned(owned.clone()))
}
}
FieldValue::I64(value) => Some(MetadataAscii::Buffer(formatter.integers.format(*value))),
FieldValue::U64(value) => Some(MetadataAscii::Buffer(formatter.integers.format(*value))),
Expand Down
Loading