agent_rooms/error.rs
1//! Parley protocol errors. Mirrors `parley/errors.py`.
2//!
3//! Each variant maps to one of the HTTP error codes in SPEC §9. The library
4//! does not produce HTTP responses; consumers translate these to their own
5//! transport.
6
7use thiserror::Error;
8
9#[derive(Debug, Error, Clone, PartialEq, Eq)]
10pub enum Error {
11 /// HTTP 400 — header pubkey malformed or not 32 bytes.
12 #[error("invalid pubkey")]
13 InvalidPubkey,
14
15 /// HTTP 400 — `created_at` outside the +/- 60 s window.
16 #[error("created_at outside acceptable window")]
17 StaleTimestamp,
18
19 /// HTTP 401 — Ed25519 verification failed, or sig not 64 bytes of hex.
20 #[error("invalid signature")]
21 BadSignature,
22
23 /// HTTP 403 — caller's pubkey not in the room, or not authorized for close.
24 #[error("not a participant of this room")]
25 NotAParticipant,
26
27 /// HTTP 403 — caller is a participant but not the current `turn_owner`.
28 #[error("not your turn")]
29 NotTurnOwner,
30
31 /// HTTP 404 — room UUID does not resolve.
32 #[error("room not found")]
33 RoomNotFound,
34
35 /// HTTP 409 — room is `closed` or past `ttl_until`.
36 #[error("room is closed or expired")]
37 RoomClosed,
38
39 /// HTTP 409 — `turn_n != room.turn_n + 1`.
40 #[error("turn_n conflict: expected {expected}, got {got}")]
41 TurnConflict { expected: i64, got: i64 },
42
43 /// HTTP 409 — duplicate `create_room` signed payload within the window.
44 #[error("duplicate signed payload within freshness window")]
45 ReplayDetected,
46
47 /// HTTP 413 — message body byte-length > 16 384.
48 #[error("message body too large")]
49 BodyTooLarge,
50
51 /// Malformed JSON input passed into a library helper.
52 #[error("invalid json: {0}")]
53 InvalidJson(String),
54
55 /// Hex decoding failure on a pubkey / signature.
56 #[error("invalid hex: {0}")]
57 InvalidHex(String),
58}