ts_client/error.rs
1// Copyright (c) 2026 LightSeek Foundation
2//
3// Permission is hereby granted, free of charge, to any person obtaining a copy
4// of this software and associated documentation files (the "Software"), to deal
5// in the Software without restriction, including without limitation the rights
6// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7// copies of the Software, and to permit persons to whom the Software is
8// furnished to do so, subject to the following conditions:
9//
10// The above copyright notice and this permission notice shall be included in
11// all copies or substantial portions of the Software.
12//
13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19// SOFTWARE.
20
21//! Client errors.
22
23use std::time::Duration;
24
25/// An error from connecting to the engines or submitting a request.
26#[derive(Debug, thiserror::Error)]
27pub enum Error {
28 /// A socket operation failed.
29 #[error("zmq: {0}")]
30 Zmq(#[from] zeromq::ZmqError),
31 /// A message did not match the wire schema.
32 #[error("wire: {0}")]
33 Wire(#[from] ts_wire::Error),
34 /// Not every engine finished a handshake stage in time.
35 #[error("handshake timed out after {timeout:?} waiting for {stage} from engines {pending:?}")]
36 HandshakeTimeout {
37 /// The stage that did not complete.
38 stage: &'static str,
39 /// Engine indices that had not completed it.
40 pending: Vec<u16>,
41 /// The configured handshake timeout.
42 timeout: Duration,
43 },
44 /// An engine broke the handshake protocol.
45 #[error("handshake: {0}")]
46 Handshake(String),
47 /// The request cannot be submitted as given.
48 #[error("invalid request: {0}")]
49 InvalidRequest(String),
50 /// A request with this id is already in flight.
51 #[error("request id `{0}` is already in flight")]
52 DuplicateRequestId(String),
53 /// The engine did not accept the message in time.
54 #[error("sending to engine {engine_index} timed out after {timeout:?}")]
55 SendTimeout {
56 /// The engine the message was for.
57 engine_index: u16,
58 /// The configured send timeout.
59 timeout: Duration,
60 },
61 /// The engines are gone; see [`StreamError`] for why.
62 #[error("engines unavailable: {0}")]
63 Unavailable(StreamError),
64}
65
66/// Why a request's output stream ended without a finished output.
67#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
68pub enum StreamError {
69 /// An engine announced its shutdown. On this wire the announcement does
70 /// not say which engine, and an engine group cannot serve with a rank
71 /// missing, so every stream ends.
72 #[error("an engine shut down")]
73 EngineDead,
74 /// The output socket failed.
75 #[error("output socket failed: {0}")]
76 Transport(String),
77 /// The client was dropped.
78 #[error("the client was dropped")]
79 ClientClosed,
80}
81
82/// Result alias for client operations.
83pub type Result<T> = std::result::Result<T, Error>;