pravega_wire_protocol/
error.rs

1//
2// Copyright (c) Dell Inc., or its subsidiaries. All Rights Reserved.
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10
11use crate::wire_commands::Replies;
12use bincode2::Error as BincodeError;
13use pravega_client_config::connection_type::ConnectionType;
14use pravega_client_shared::PravegaNodeUri;
15use snafu::{Backtrace, Snafu};
16use std::io::Error as IoError;
17
18/// This kind of error that can be produced during Pravega client connecting to server.
19#[derive(Debug, Snafu)]
20#[snafu(visibility = "pub(crate)")]
21pub enum ConnectionError {
22    #[snafu(display("Could not send data to {:?} asynchronously: {}", endpoint, source))]
23    SendData {
24        endpoint: PravegaNodeUri,
25        source: std::io::Error,
26        backtrace: Backtrace,
27    },
28    #[snafu(display("Could not read data from {:?} asynchronously: {}", endpoint, source))]
29    ReadData {
30        endpoint: PravegaNodeUri,
31        source: std::io::Error,
32        backtrace: Backtrace,
33    },
34}
35
36#[derive(Debug, Snafu)]
37#[snafu(visibility = "pub(crate)")]
38pub enum ConnectionFactoryError {
39    #[snafu(display(
40        "Could not connect to endpoint {:?} using connection type {}: {}",
41        endpoint,
42        connection_type,
43        source
44    ))]
45    Connect {
46        connection_type: ConnectionType,
47        endpoint: PravegaNodeUri,
48        source: std::io::Error,
49        backtrace: Backtrace,
50    },
51
52    #[snafu(display("Failed to verify the connection: {}", source))]
53    Verify { source: ClientConnectionError },
54}
55
56/// This kind of error that can be produced during Pravega serialize and deserialize the wire commands.
57#[derive(Debug, Snafu)]
58#[snafu(visibility = "pub(crate)")]
59pub enum CommandError {
60    #[snafu(display(
61        "Could not serialize/deserialize command {} because of: {}",
62        command_type,
63        source
64    ))]
65    InvalidData {
66        command_type: i32,
67        source: BincodeError,
68        backtrace: Backtrace,
69    },
70    #[snafu(display(
71        "Could not serialize/deserialize command {} because of: {}",
72        command_type,
73        source
74    ))]
75    Io {
76        command_type: i32,
77        source: IoError,
78        backtrace: Backtrace,
79    },
80    #[snafu(display(
81        "Could not serialize/deserialize command {} because of: Unknown Command",
82        command_type
83    ))]
84    InvalidType { command_type: i32, backtrace: Backtrace },
85}
86
87/// This kind of error that can be produced during Pravega client connection.
88#[derive(Debug, Snafu)]
89#[snafu(visibility = "pub(crate)")]
90pub enum ClientConnectionError {
91    #[snafu(display("Failed to read wirecommand {} : {}", part, source))]
92    Read {
93        part: String,
94        source: ConnectionError,
95        backtrace: Backtrace,
96    },
97
98    #[snafu(display("Failed to write wirecommand: {}", source))]
99    Write {
100        source: ConnectionError,
101        backtrace: Backtrace,
102    },
103
104    #[snafu(display(
105        "The payload size {} exceeds the max wirecommand size {}",
106        payload_size,
107        max_wirecommand_size
108    ))]
109    PayloadLengthTooLong {
110        payload_size: u32,
111        max_wirecommand_size: u32,
112        backtrace: Backtrace,
113    },
114
115    #[snafu(display("Failed to encode wirecommand: {}", source))]
116    EncodeCommand {
117        source: CommandError,
118        backtrace: Backtrace,
119    },
120
121    #[snafu(display("Failed to decode wirecommand: {}", source))]
122    DecodeCommand {
123        source: CommandError,
124        backtrace: Backtrace,
125    },
126
127    #[snafu(display("Failed to write/read since connection is split"))]
128    ConnectionIsSplit {},
129
130    #[snafu(display("Wrong Hello Wirecommand reply: current wire version {} and oldest compatible version {}, but get {} and {}", wire_version, oldest_compatible, wire_version_received, oldest_compatible_received))]
131    WrongHelloVersion {
132        wire_version: i32,
133        oldest_compatible: i32,
134        wire_version_received: i32,
135        oldest_compatible_received: i32,
136    },
137
138    #[snafu(display("Expect to receive Hello Wirecommand but get {}", reply))]
139    WrongReply { reply: Replies },
140}