matrix_pickle/
error.rs

1// Copyright 2021, 2022 Damir Jelić
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use thiserror::Error;
16
17/// Error type describing failure modes for libolm pickle decoding.
18#[derive(Debug, Error)]
19pub enum DecodeError {
20    /// There was an error while reading from the source of the libolm, usually
21    /// not enough data was provided.
22    #[error(transparent)]
23    IO(#[from] std::io::Error),
24    /// The encoded usize doesn't fit into the usize of the architecture that is
25    /// decoding.
26    #[error(
27        "The decoded value {0} does not fit into the usize type of this \
28         architecture"
29    )]
30    OutsideUsizeRange(u64),
31    /// An array in the pickle has too many elements.
32    #[error("An array has too many elements: {0}")]
33    ArrayTooBig(usize),
34    /// TODO
35    #[error("TODO {0}")]
36    UnknownEnumVariant(u8),
37}
38
39/// Error type describing failure modes for libolm pickle decoding.
40#[derive(Debug, Error)]
41pub enum EncodeError {
42    /// There was an error while writing to the buffer.
43    #[error(transparent)]
44    IO(#[from] std::io::Error),
45    /// The usize value that should be encoded doesn't fit into the u32 range of
46    /// values.
47    #[error("The usize value {0} does not fit into the u32 range of values.")]
48    OutsideU32Range(usize),
49    /// An array in the pickle has too many elements.
50    #[error("An array has too many elements: {0}")]
51    ArrayTooBig(usize),
52}