value_log/
error.rs

1// Copyright (c) 2024-present, fjall-rs
2// This source code is licensed under both the Apache 2.0 and MIT License
3// (found in the LICENSE-* files in the repository)
4
5use crate::{
6    coding::{DecodeError, EncodeError},
7    version::Version,
8};
9
10/// Represents errors that can occur in the value log
11#[derive(Debug)]
12#[non_exhaustive]
13pub enum Error {
14    /// I/O error
15    Io(std::io::Error),
16
17    /// Invalid data format version
18    InvalidVersion(Option<Version>),
19
20    /// Serialization failed
21    Encode(EncodeError),
22
23    /// Deserialization failed
24    Decode(DecodeError),
25
26    /// Compression failed
27    Compress,
28
29    /// Decompression failed
30    Decompress,
31    // TODO:
32    // /// Checksum check failed
33    // ChecksumMismatch,
34}
35
36impl std::fmt::Display for Error {
37    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
38        write!(f, "ValueLogError: {self:?}")
39    }
40}
41
42impl std::error::Error for Error {}
43
44impl From<std::io::Error> for Error {
45    fn from(value: std::io::Error) -> Self {
46        Self::Io(value)
47    }
48}
49
50impl From<EncodeError> for Error {
51    fn from(value: EncodeError) -> Self {
52        Self::Encode(value)
53    }
54}
55
56impl From<DecodeError> for Error {
57    fn from(value: DecodeError) -> Self {
58        Self::Decode(value)
59    }
60}
61
62/// Value log result
63pub type Result<T> = std::result::Result<T, Error>;