|
| 1 | +use std::error::Error; |
1 | 2 | use std::sync::Arc; |
2 | 3 |
|
| 4 | +pub use super::request::{ |
| 5 | + auth_response::AuthResponseSerializationError, |
| 6 | + batch::{BatchSerializationError, BatchStatementSerializationError}, |
| 7 | + execute::ExecuteSerializationError, |
| 8 | + prepare::PrepareSerializationError, |
| 9 | + query::{QueryParametersSerializationError, QuerySerializationError}, |
| 10 | + register::RegisterSerializationError, |
| 11 | + startup::StartupSerializationError, |
| 12 | +}; |
| 13 | + |
3 | 14 | use super::response::CqlResponseKind; |
4 | 15 | use super::TryFromPrimitiveError; |
5 | | -use crate::cql_to_rust::CqlTypeError; |
6 | | -use crate::frame::value::SerializeValuesError; |
7 | | -use crate::types::deserialize::{DeserializationError, TypeCheckError}; |
8 | | -use crate::types::serialize::SerializationError; |
| 16 | +use crate::types::deserialize::DeserializationError; |
9 | 17 | use thiserror::Error; |
10 | 18 |
|
11 | | -#[derive(Error, Debug)] |
12 | | -pub enum FrameError { |
13 | | - #[error(transparent)] |
14 | | - Parse(#[from] ParseError), |
| 19 | +/// An error returned by `parse_response_body_extensions`. |
| 20 | +/// |
| 21 | +/// It represents an error that occurred during deserialization of |
| 22 | +/// frame body extensions. These extensions include tracing id, |
| 23 | +/// warnings and custom payload. |
| 24 | +/// |
| 25 | +/// Possible error kinds: |
| 26 | +/// - failed to decompress frame body (decompression is required for further deserialization) |
| 27 | +/// - failed to deserialize tracing id (body ext.) |
| 28 | +/// - failed to deserialize warnings list (body ext.) |
| 29 | +/// - failed to deserialize custom payload map (body ext.) |
| 30 | +#[derive(Error, Debug, Clone)] |
| 31 | +#[non_exhaustive] |
| 32 | +pub enum FrameBodyExtensionsParseError { |
| 33 | + /// Frame is compressed, but no compression was negotiated for the connection. |
15 | 34 | #[error("Frame is compressed, but no compression negotiated for connection.")] |
16 | 35 | NoCompressionNegotiated, |
| 36 | + |
| 37 | + /// Failed to deserialize frame trace id. |
| 38 | + #[error("Malformed trace id: {0}")] |
| 39 | + TraceIdParse(LowLevelDeserializationError), |
| 40 | + |
| 41 | + /// Failed to deserialize warnings attached to frame. |
| 42 | + #[error("Malformed warnings list: {0}")] |
| 43 | + WarningsListParse(LowLevelDeserializationError), |
| 44 | + |
| 45 | + /// Failed to deserialize frame's custom payload. |
| 46 | + #[error("Malformed custom payload map: {0}")] |
| 47 | + CustomPayloadMapParse(LowLevelDeserializationError), |
| 48 | + |
| 49 | + /// Failed to decompress frame body (snap). |
| 50 | + #[error("Snap decompression error: {0}")] |
| 51 | + SnapDecompressError(Arc<dyn Error + Sync + Send>), |
| 52 | + |
| 53 | + /// Failed to decompress frame body (lz4). |
| 54 | + #[error("Error decompressing lz4 data {0}")] |
| 55 | + Lz4DecompressError(Arc<dyn Error + Sync + Send>), |
| 56 | +} |
| 57 | + |
| 58 | +/// An error that occurred during frame header deserialization. |
| 59 | +#[derive(Debug, Error)] |
| 60 | +#[non_exhaustive] |
| 61 | +pub enum FrameHeaderParseError { |
| 62 | + /// Failed to read the frame header from the socket. |
| 63 | + #[error("Failed to read the frame header: {0}")] |
| 64 | + HeaderIoError(std::io::Error), |
| 65 | + |
| 66 | + /// Received a frame marked as coming from a client. |
17 | 67 | #[error("Received frame marked as coming from a client")] |
18 | 68 | FrameFromClient, |
| 69 | + |
| 70 | + // FIXME: this should not belong here. User always expects a frame from server. |
| 71 | + // This variant is only used in scylla-proxy - need to investigate it later. |
19 | 72 | #[error("Received frame marked as coming from the server")] |
20 | 73 | FrameFromServer, |
| 74 | + |
| 75 | + /// Received a frame with unsupported version. |
21 | 76 | #[error("Received a frame from version {0}, but only 4 is supported")] |
22 | 77 | VersionNotSupported(u8), |
| 78 | + |
| 79 | + /// Received unknown response opcode. |
| 80 | + #[error("Unrecognized response opcode {0}")] |
| 81 | + UnknownResponseOpcode(#[from] TryFromPrimitiveError<u8>), |
| 82 | + |
| 83 | + /// Failed to read frame body from the socket. |
| 84 | + #[error("Failed to read a chunk of response body. Expected {0} more bytes, error: {1}")] |
| 85 | + BodyChunkIoError(usize, std::io::Error), |
| 86 | + |
| 87 | + /// Connection was closed before whole frame was read. |
23 | 88 | #[error("Connection was closed before body was read: missing {0} out of {1}")] |
24 | 89 | ConnectionClosed(usize, usize), |
25 | | - #[error("Frame decompression failed.")] |
26 | | - FrameDecompression, |
27 | | - #[error("Frame compression failed.")] |
28 | | - FrameCompression, |
29 | | - #[error(transparent)] |
30 | | - StdIoError(#[from] std::io::Error), |
31 | | - #[error("Unrecognized opcode{0}")] |
32 | | - TryFromPrimitiveError(#[from] TryFromPrimitiveError<u8>), |
33 | | - #[error("Error compressing lz4 data {0}")] |
34 | | - Lz4CompressError(#[from] lz4_flex::block::CompressError), |
35 | | - #[error("Error decompressing lz4 data {0}")] |
36 | | - Lz4DecompressError(#[from] lz4_flex::block::DecompressError), |
37 | 90 | } |
38 | 91 |
|
39 | | -#[derive(Error, Debug)] |
40 | | -pub enum ParseError { |
41 | | - #[error("Low-level deserialization failed: {0}")] |
42 | | - LowLevelDeserializationError(#[from] LowLevelDeserializationError), |
43 | | - #[error("Could not serialize frame: {0}")] |
44 | | - BadDataToSerialize(String), |
45 | | - #[error("Could not deserialize frame: {0}")] |
46 | | - BadIncomingData(String), |
47 | | - #[error(transparent)] |
48 | | - DeserializationError(#[from] DeserializationError), |
49 | | - #[error(transparent)] |
50 | | - DeserializationTypeCheckError(#[from] TypeCheckError), |
51 | | - #[error(transparent)] |
52 | | - IoError(#[from] std::io::Error), |
53 | | - #[error(transparent)] |
54 | | - SerializeValuesError(#[from] SerializeValuesError), |
55 | | - #[error(transparent)] |
56 | | - SerializationError(#[from] SerializationError), |
57 | | - #[error(transparent)] |
58 | | - CqlTypeError(#[from] CqlTypeError), |
| 92 | +/// An error that occurred during CQL request serialization. |
| 93 | +#[non_exhaustive] |
| 94 | +#[derive(Error, Debug, Clone)] |
| 95 | +pub enum CqlRequestSerializationError { |
| 96 | + /// Failed to serialize STARTUP request. |
| 97 | + #[error("Failed to serialize STARTUP request: {0}")] |
| 98 | + StartupSerialization(#[from] StartupSerializationError), |
| 99 | + |
| 100 | + /// Failed to serialize REGISTER request. |
| 101 | + #[error("Failed to serialize REGISTER request: {0}")] |
| 102 | + RegisterSerialization(#[from] RegisterSerializationError), |
| 103 | + |
| 104 | + /// Failed to serialize AUTH_RESPONSE request. |
| 105 | + #[error("Failed to serialize AUTH_RESPONSE request: {0}")] |
| 106 | + AuthResponseSerialization(#[from] AuthResponseSerializationError), |
| 107 | + |
| 108 | + /// Failed to serialize BATCH request. |
| 109 | + #[error("Failed to serialize BATCH request: {0}")] |
| 110 | + BatchSerialization(#[from] BatchSerializationError), |
| 111 | + |
| 112 | + /// Failed to serialize PREPARE request. |
| 113 | + #[error("Failed to serialize PREPARE request: {0}")] |
| 114 | + PrepareSerialization(#[from] PrepareSerializationError), |
| 115 | + |
| 116 | + /// Failed to serialize EXECUTE request. |
| 117 | + #[error("Failed to serialize EXECUTE request: {0}")] |
| 118 | + ExecuteSerialization(#[from] ExecuteSerializationError), |
| 119 | + |
| 120 | + /// Failed to serialize QUERY request. |
| 121 | + #[error("Failed to serialize QUERY request: {0}")] |
| 122 | + QuerySerialization(#[from] QuerySerializationError), |
| 123 | + |
| 124 | + /// Request body compression failed. |
| 125 | + #[error("Snap compression error: {0}")] |
| 126 | + SnapCompressError(Arc<dyn Error + Sync + Send>), |
59 | 127 | } |
60 | 128 |
|
61 | 129 | /// An error type returned when deserialization of CQL |
|
0 commit comments