thunder/server/errors.rs
1//! Error-string helpers for the two modelled conventions (SRV-021).
2//!
3//! `Response.result` errors are plain strings that travel verbatim
4//! (WIRE-040); Thunder models exactly two prefix conventions — the
5//! RESP3-style tokens `ERR`/`NOAUTH`/`WRONGPASS`/`NOPERM`, and the
6//! bracket-code form `"[code] message"`. `ErrorConvention::Both` composes
7//! them and is the standard, because a superset needs no negotiation.
8//! These helpers exist so applications never hand-roll the spellings.
9
10/// Family-pinned auth-required error (`Resp3Prefixes`, SRV-011).
11pub const NOAUTH: &str = "NOAUTH Authentication required.";
12
13/// Family-pinned bad-credentials error (`Resp3Prefixes`).
14pub const WRONGPASS: &str = "WRONGPASS invalid username-password pair or user is disabled.";
15
16/// Family-pinned insufficient-privilege error (`Resp3Prefixes`).
17///
18/// Thunder's listener never emits this itself — authorization beyond the
19/// handshake is the product's, raised from its [`Dispatch`](super::Dispatch)
20/// — but Synap ships exactly this token for its admin ACL, so the family
21/// pins one spelling instead of letting each product invent another. Clients
22/// classify it as an auth-class error (CLT-051).
23pub const NOPERM: &str = "NOPERM this command requires admin privileges";
24
25/// Format the machine-readable convention: `"[<code>] <message>"`
26/// (PRO-014 `BracketCode`).
27pub fn format_bracket_code(code: &str, message: &str) -> String {
28 format!("[{code}] {message}")
29}
30
31/// Format the generic-error convention: `"ERR <message>"`
32/// (PRO-014 `Resp3Prefixes`).
33pub fn format_err(message: &str) -> String {
34 format!("ERR {message}")
35}