Skip to main content

fluss/rpc/
error.rs

1// Licensed to the Apache Software Foundation (ASF) under one
2// or more contributor license agreements.  See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership.  The ASF licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License.  You may obtain a copy of the License at
8//
9//   http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied.  See the License for the
15// specific language governing permissions and limitations
16// under the License.
17
18use crate::rpc::api_key::ApiKey;
19use crate::rpc::api_version::ApiVersion;
20use prost::DecodeError;
21use std::sync::Arc;
22use thiserror::Error;
23
24#[derive(Error, Debug)]
25#[non_exhaustive]
26pub enum RpcError {
27    #[error("Cannot write message: {0}")]
28    WriteMessageError(#[from] crate::rpc::frame::WriteError),
29
30    #[error("Cannot read framed message: {0}")]
31    ReadMessageError(#[from] crate::rpc::frame::ReadError),
32
33    #[error("Rpc Decode Error: {0}")]
34    RpcDecodeError(#[from] DecodeError),
35
36    #[error("connection error")]
37    ConnectionError(String),
38
39    #[error("IO Error: {0}")]
40    IO(#[from] std::io::Error),
41
42    #[error("Connection is poisoned: {0}")]
43    Poisoned(Arc<RpcError>),
44
45    #[error(
46        "Data left at the end of the message. Got {message_size} bytes but only read {read} bytes. api_key={api_key:?} api_version={api_version}"
47    )]
48    TooMuchData {
49        message_size: u64,
50        read: u64,
51        api_key: ApiKey,
52        api_version: ApiVersion,
53    },
54}