1use std::fmt;
4
5pub const NO_ERROR: u64 = 0x0;
6pub const INTERNAL_ERROR: u64 = 0x1;
7pub const CONNECTION_REFUSED: u64 = 0x2;
8pub const FLOW_CONTROL_ERROR: u64 = 0x3;
9pub const STREAM_LIMIT_ERROR: u64 = 0x4;
10pub const STREAM_STATE_ERROR: u64 = 0x5;
11pub const FINAL_SIZE_ERROR: u64 = 0x6;
12pub const FRAME_ENCODING_ERROR: u64 = 0x7;
13pub const TRANSPORT_PARAMETER_ERROR: u64 = 0x8;
14pub const CONNECTION_ID_LIMIT_ERROR: u64 = 0x9;
15pub const PROTOCOL_VIOLATION: u64 = 0xa;
16pub const INVALID_TOKEN: u64 = 0xb;
17pub const APPLICATION_ERROR: u64 = 0xc;
18pub const CRYPTO_BUFFER_EXCEEDED: u64 = 0xd;
19pub const KEY_UPDATE_ERROR: u64 = 0xe;
20pub const AEAD_LIMIT_REACHED: u64 = 0xf;
21pub const NO_VIABLE_PATH: u64 = 0x10;
22pub const CRYPTO_ERROR: u64 = 0x100;
24
25#[derive(Clone, Debug, PartialEq, Eq)]
27pub struct TransportError {
28 pub code: u64,
29 pub frame_type: u64,
30 pub reason: &'static str,
31}
32
33impl TransportError {
34 pub const fn new(code: u64, reason: &'static str) -> Self {
35 TransportError { code, frame_type: 0, reason }
36 }
37 pub const fn frame(code: u64, frame_type: u64, reason: &'static str) -> Self {
38 TransportError { code, frame_type, reason }
39 }
40 pub const fn proto(reason: &'static str) -> Self {
41 Self::new(PROTOCOL_VIOLATION, reason)
42 }
43 pub const fn encoding(reason: &'static str) -> Self {
44 Self::new(FRAME_ENCODING_ERROR, reason)
45 }
46}
47
48impl fmt::Display for TransportError {
49 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
50 write!(f, "transport error 0x{:x}: {}", self.code, self.reason)
51 }
52}
53
54impl std::error::Error for TransportError {}
55
56#[derive(Clone, Copy, Debug, PartialEq, Eq)]
58pub enum StreamError {
59 UnknownStream,
61 InvalidDirection,
63 Blocked,
65 WouldBlock,
67 Stopped(u64),
69 Reset(u64),
71 Finished,
73 LimitReached,
75 ConnectionClosed,
77}
78
79impl fmt::Display for StreamError {
80 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
81 fmt::Debug::fmt(self, f)
82 }
83}
84
85impl std::error::Error for StreamError {}