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

## [Unreleased]

## [0.4.0] - 2025-09-15
### Added
- Optional `frontend` feature:
- Converts [`AppError`] and [`ErrorResponse`] into `wasm_bindgen::JsValue` for browser contexts.
- Logs structured errors to the browser console via `console.error`.
- `BrowserConsoleError` and `BrowserConsoleExt` API for WASM front-ends.

### Documentation
- Documented browser/WASM support and console logging workflow in the README and crate docs.

## [0.3.5] - 2025-09-12
### Added
- Conversion from `teloxide_core::RequestError` into `AppError` (feature `teloxide`).
Expand Down Expand Up @@ -111,4 +121,5 @@ All notable changes to this project will be documented in this file.
[0.3.0]: https://github.com/RAprogramm/masterror/releases/tag/v0.3.0
[0.2.1]: https://github.com/RAprogramm/masterror/releases/tag/v0.2.1
[0.2.0]: https://github.com/RAprogramm/masterror/releases/tag/v0.2.0
[0.4.0]: https://github.com/RAprogramm/masterror/releases/tag/v0.4.0

5 changes: 4 additions & 1 deletion Cargo.lock

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

6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "masterror"
version = "0.3.5"
version = "0.4.0"
rust-version = "1.89"
edition = "2024"
description = "Application error types and response mapping"
Expand All @@ -26,6 +26,7 @@ tokio = ["dep:tokio"]
reqwest = ["dep:reqwest"]
teloxide = ["dep:teloxide-core"]
telegram-webapp-sdk = ["dep:telegram-webapp-sdk"]
frontend = ["dep:wasm-bindgen", "dep:js-sys", "dep:serde-wasm-bindgen"]
turnkey = []

openapi = ["dep:utoipa"]
Expand Down Expand Up @@ -58,6 +59,9 @@ tokio = { version = "1", optional = true, features = ["time"] }
reqwest = { version = "0.12", optional = true, default-features = false }
teloxide-core = { version = "0.13", optional = true, default-features = false }
telegram-webapp-sdk = { version = "0.1", optional = true }
wasm-bindgen = { version = "0.2", optional = true }
js-sys = { version = "0.3", optional = true }
serde-wasm-bindgen = { version = "0.6", optional = true }

[dev-dependencies]
serde_json = "1"
Expand Down
43 changes: 35 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ Stable categories, conservative HTTP mapping, no `unsafe`.

~~~toml
[dependencies]
masterror = { version = "0.3", default-features = false }
masterror = { version = "0.4", default-features = false }
# or with features:
# masterror = { version = "0.3", features = [
# masterror = { version = "0.4", features = [
# "axum", "actix", "serde_json", "openapi",
# "sqlx", "reqwest", "redis", "validator", "config", "tokio", "teloxide"
# ] }
~~~

*Since v0.4.0: optional `frontend` feature for WASM/browser console logging.*
*Since v0.3.0: stable `AppCode` enum and extended `ErrorResponse` with retry/authentication metadata.*

---
Expand All @@ -53,10 +54,10 @@ masterror = { version = "0.3", default-features = false }
~~~toml
[dependencies]
# lean core
masterror = { version = "0.3", default-features = false }
masterror = { version = "0.4", default-features = false }

# with Axum/Actix + JSON + integrations
# masterror = { version = "0.3", features = [
# masterror = { version = "0.4", features = [
# "axum", "actix", "serde_json", "openapi",
# "sqlx", "reqwest", "redis", "validator", "config", "tokio", "teloxide"
# ] }
Expand Down Expand Up @@ -160,12 +161,37 @@ async fn payload() -> impl Responder {

~~~toml
[dependencies]
masterror = { version = "0.3", features = ["openapi", "serde_json"] }
masterror = { version = "0.4", features = ["openapi", "serde_json"] }
utoipa = "5"
~~~

</details>

<details>
<summary><b>Browser (WASM)</b></summary>

~~~rust
// features = ["frontend"]
use masterror::{AppError, AppErrorKind};
use masterror::frontend::{BrowserConsoleError, BrowserConsoleExt};

fn report() -> Result<(), BrowserConsoleError> {
let err = AppError::bad_request("missing field");
let payload = err.to_js_value()?;
assert!(payload.is_object());

#[cfg(target_arch = "wasm32")]
err.log_to_browser_console()?;

Ok(())
}
~~~

- On non-WASM targets `log_to_browser_console` returns
`BrowserConsoleError::UnsupportedTarget`.

</details>

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

Expand All @@ -174,6 +200,7 @@ utoipa = "5"
- `openapi` — utoipa schema
- `serde_json` — JSON details
- `sqlx`, `redis`, `reqwest`, `validator`, `config`, `tokio`, `multipart`, `teloxide`, `telegram-webapp-sdk`
- `frontend` — convert errors into `JsValue` and log via `console.error` (WASM)
- `turnkey` — domain taxonomy and conversions for Turnkey errors

</details>
Expand Down Expand Up @@ -201,13 +228,13 @@ utoipa = "5"
Minimal core:

~~~toml
masterror = { version = "0.3", default-features = false }
masterror = { version = "0.4", default-features = false }
~~~

API (Axum + JSON + deps):

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

~~~toml
masterror = { version = "0.3", features = [
masterror = { version = "0.4", features = [
"actix", "serde_json", "openapi",
"sqlx", "reqwest", "redis", "validator", "config", "tokio"
] }
Expand Down
12 changes: 6 additions & 6 deletions src/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@
//! ```rust
//! use std::io::{self, ErrorKind};
//!
//! use masterror::{AppError, AppErrorKind};
//! use masterror::{AppError, AppErrorKind, AppResult};
//!
//! fn open() -> Result<(), AppError> {
//! fn open() -> AppResult<()> {
//! let _ = io::Error::new(ErrorKind::Other, "boom");
//! Err(io::Error::from(ErrorKind::Other).into())
//! }
Expand All @@ -61,9 +61,9 @@
//! feature):
//!
//! ```rust
//! use masterror::{AppError, AppErrorKind};
//! use masterror::{AppError, AppErrorKind, AppResult};
//!
//! fn validate(x: i32) -> Result<(), AppError> {
//! fn validate(x: i32) -> AppResult<()> {
//! if x < 0 {
//! return Err(String::from("must be non-negative").into());
//! }
Expand Down Expand Up @@ -149,9 +149,9 @@ impl From<IoError> for AppError {
/// Prefer structured validation for complex DTOs, but this covers simple cases.
///
/// ```rust
/// use masterror::{AppError, AppErrorKind};
/// use masterror::{AppError, AppErrorKind, AppResult};
///
/// fn check(name: &str) -> Result<(), AppError> {
/// fn check(name: &str) -> AppResult<()> {
/// if name.is_empty() {
/// return Err(String::from("name must not be empty").into());
/// }
Expand Down
2 changes: 1 addition & 1 deletion src/convert/actix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//!
//! ## What it does
//! - Implements `actix_web::ResponseError` for [`AppError`].
//! - This lets you `return Result<_, AppError>` from Actix handlers.
//! - This lets you `return AppResult<_>` from Actix handlers.
//! - On error, Actix automatically builds an `HttpResponse` with the right
//! status code and JSON body (when the `serde_json` feature is enabled).
//! - Provides stable mapping from [`AppErrorKind`] to
Expand Down
4 changes: 2 additions & 2 deletions src/convert/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
//! ## Example
//!
//! ```rust,ignore
//! use masterror::{AppError, AppErrorKind};
//! use masterror::{AppError, AppErrorKind, AppResult};
//! use validator::{Validate, ValidationError};
//!
//! #[derive(Validate)]
Expand All @@ -28,7 +28,7 @@
//! name: String,
//! }
//!
//! fn validate_payload(p: Payload) -> Result<(), AppError> {
//! fn validate_payload(p: Payload) -> AppResult<()> {
//! p.validate()?;
//! Ok(())
//! }
Expand Down
Loading