alopex_core/columnar/
error.rs

1//! カラムナー処理専用のエラー型と結果型。
2use thiserror::Error;
3
4use crate::Error as CoreError;
5
6/// カラムナー系処理用の結果型。
7pub type Result<T> = std::result::Result<T, ColumnarError>;
8
9/// カラムナー処理で発生するエラー。
10#[derive(Debug, Error)]
11pub enum ColumnarError {
12    /// チェックサムが一致しない。
13    #[error("checksum mismatch")]
14    ChecksumMismatch,
15    /// サポートされないフォーマットバージョン。
16    #[error("unsupported format version: found={found}, expected={expected}")]
17    UnsupportedFormatVersion {
18        /// 実際に検出したバージョン。
19        found: u16,
20        /// 期待するバージョン。
21        expected: u16,
22    },
23    /// サポートされない圧縮方式。
24    #[error("unsupported compression: {algorithm}")]
25    UnsupportedCompression {
26        /// 圧縮アルゴリズムの識別子。
27        algorithm: String,
28    },
29    /// メモリ上限を超過した。
30    #[error("memory limit exceeded: limit={limit}, requested={requested}")]
31    MemoryLimitExceeded {
32        /// 許容上限(バイト)。
33        limit: usize,
34        /// 要求サイズ(バイト)。
35        requested: usize,
36    },
37    /// フォーマットが不正。
38    #[error("invalid format: {0}")]
39    InvalidFormat(String),
40    /// リソースが存在しない。
41    #[error("not found")]
42    NotFound,
43    /// 取引の競合。
44    #[error("transaction conflict")]
45    TxnConflict,
46    /// RowGroup が許容サイズを超えた。
47    #[error("row group too large: size={size}, max={max}")]
48    RowGroupTooLarge {
49        /// RowGroup のサイズ(バイト)。
50        size: u64,
51        /// 許容上限(バイト)。
52        max: u64,
53    },
54    /// In-memory モードでのみ許可される操作。
55    #[error("not in in-memory mode")]
56    NotInMemoryMode,
57    /// テーブルが存在しない。
58    #[error("table not found: {table}")]
59    TableNotFound {
60        /// 見つからなかったテーブル名。
61        table: String,
62    },
63    /// セグメントが壊れている、またはフォーマットが不正。
64    #[error("corrupted segment: {reason}")]
65    CorruptedSegment {
66        /// 壊れている理由。
67        reason: String,
68    },
69    /// エンコード/デコードに失敗。
70    #[error("encoding error: {reason}")]
71    EncodingError {
72        /// 失敗理由。
73        reason: String,
74    },
75    /// I/O エラー。
76    #[error("io error: {0}")]
77    Io(#[from] std::io::Error),
78}
79
80impl From<CoreError> for ColumnarError {
81    fn from(err: CoreError) -> Self {
82        match err {
83            CoreError::ChecksumMismatch => ColumnarError::ChecksumMismatch,
84            CoreError::InvalidFormat(reason) => ColumnarError::InvalidFormat(reason),
85            CoreError::CorruptedSegment { reason } => ColumnarError::CorruptedSegment { reason },
86            CoreError::MemoryLimitExceeded { limit, requested } => {
87                ColumnarError::MemoryLimitExceeded { limit, requested }
88            }
89            CoreError::TxnConflict => ColumnarError::TxnConflict,
90            CoreError::NotFound => ColumnarError::NotFound,
91            CoreError::Io(e) => ColumnarError::Io(e),
92            other => ColumnarError::EncodingError {
93                reason: other.to_string(),
94            },
95        }
96    }
97}