Skip to main content

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    /// Bounded streaming requires a provisioned V08 chunked segment layout.
24    #[error("requires V08 chunked layout")]
25    RequiresV08ChunkedLayout,
26    /// サポートされない圧縮方式。
27    #[error("unsupported compression: {algorithm}")]
28    UnsupportedCompression {
29        /// 圧縮アルゴリズムの識別子。
30        algorithm: String,
31    },
32    /// メモリ上限を超過した。
33    #[error("memory limit exceeded: limit={limit}, requested={requested}")]
34    MemoryLimitExceeded {
35        /// 許容上限(バイト)。
36        limit: usize,
37        /// 要求サイズ(バイト)。
38        requested: usize,
39    },
40    /// フォーマットが不正。
41    #[error("invalid format: {0}")]
42    InvalidFormat(String),
43    /// リソースが存在しない。
44    #[error("not found")]
45    NotFound,
46    /// 取引の競合。
47    #[error("transaction conflict")]
48    TxnConflict,
49    /// RowGroup が許容サイズを超えた。
50    #[error("row group too large: size={size}, max={max}")]
51    RowGroupTooLarge {
52        /// RowGroup のサイズ(バイト)。
53        size: u64,
54        /// 許容上限(バイト)。
55        max: u64,
56    },
57    /// In-memory モードでのみ許可される操作。
58    #[error("not in in-memory mode")]
59    NotInMemoryMode,
60    /// テーブルが存在しない。
61    #[error("table not found: {table}")]
62    TableNotFound {
63        /// 見つからなかったテーブル名。
64        table: String,
65    },
66    /// セグメントが壊れている、またはフォーマットが不正。
67    #[error("corrupted segment: {reason}")]
68    CorruptedSegment {
69        /// 壊れている理由。
70        reason: String,
71    },
72    /// エンコード/デコードに失敗。
73    #[error("encoding error: {reason}")]
74    EncodingError {
75        /// 失敗理由。
76        reason: String,
77    },
78    /// I/O エラー。
79    #[error("io error: {0}")]
80    Io(#[from] std::io::Error),
81}
82
83impl From<CoreError> for ColumnarError {
84    fn from(err: CoreError) -> Self {
85        match err {
86            CoreError::ChecksumMismatch => ColumnarError::ChecksumMismatch,
87            CoreError::InvalidFormat(reason) => ColumnarError::InvalidFormat(reason),
88            CoreError::CorruptedSegment { segment_id, reason } => ColumnarError::CorruptedSegment {
89                reason: format!("segment {segment_id}: {reason}"),
90            },
91            CoreError::MemoryLimitExceeded { limit, requested } => {
92                ColumnarError::MemoryLimitExceeded { limit, requested }
93            }
94            CoreError::TxnConflict => ColumnarError::TxnConflict,
95            CoreError::NotFound => ColumnarError::NotFound,
96            CoreError::Io(e) => ColumnarError::Io(e),
97            other => ColumnarError::EncodingError {
98                reason: other.to_string(),
99            },
100        }
101    }
102}