flowcat_core/error.rs
1// SPDX-License-Identifier: Apache-2.0
2//
3//! The crate-wide error type.
4//!
5//! Every fallible trait method in flowcat-core returns `Result<_, FlowcatError>`.
6
7use thiserror::Error;
8
9/// Errors surfaced by the Flowcat runtime.
10///
11/// Variants are intentionally broad; implementation agents may add fields or
12/// new variants as needed, but should keep `FlowcatError` as the single error
13/// type that flows through the trait contracts (see DESIGN.md "Trait contracts").
14#[derive(Debug, Error)]
15pub enum FlowcatError {
16 /// The media transport / socket failed (connection closed, send error, …).
17 #[error("transport error: {0}")]
18 Transport(String),
19
20 /// A per-carrier serializer could not parse or encode a frame.
21 #[error("serializer error: {0}")]
22 Serializer(String),
23
24 /// The realtime speech-to-speech model (e.g. Gemini Live) errored.
25 #[error("realtime LLM error: {0}")]
26 Realtime(String),
27
28 /// Audio codec / resampling failure (G.711, rubato, …).
29 #[error("codec error: {0}")]
30 Codec(String),
31
32 /// Session bootstrap / finalize against the control plane failed.
33 #[error("session error: {0}")]
34 Session(String),
35
36 /// A network/HTTP call failed.
37 #[error("network error: {0}")]
38 Network(String),
39
40 /// (De)serialization of a protocol/JSON frame failed.
41 #[error("protocol error: {0}")]
42 Protocol(String),
43
44 /// Underlying JSON (de)serialization error.
45 #[error("json error: {0}")]
46 Json(#[from] serde_json::Error),
47
48 /// Underlying I/O error.
49 #[error("io error: {0}")]
50 Io(#[from] std::io::Error),
51
52 /// A catch-all for anything not yet categorized.
53 #[error("{0}")]
54 Other(String),
55}
56
57/// Convenience alias used throughout the crate.
58pub type Result<T> = std::result::Result<T, FlowcatError>;