Skip to main content

parx_rs/
error.rs

1/*
2 * Copyright 2026 PARX Authors
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17//! Error types for PARX operations.
18
19use thiserror::Error;
20
21/// Result type for PARX operations.
22pub type Result<T> = std::result::Result<T, ParxError>;
23
24/// Errors that can occur when reading or writing PARX files.
25#[derive(Error, Debug)]
26pub enum ParxError {
27    /// Invalid magic bytes in header or trailer.
28    #[error("invalid magic: expected PARX, got {0:?}")]
29    InvalidMagic([u8; 4]),
30
31    /// Unsupported PARX format version.
32    #[error("unsupported version: {major}.{minor}")]
33    UnsupportedVersion { major: u8, minor: u8 },
34
35    /// File is too small to contain valid PARX data.
36    #[error("file too small: {size} bytes, minimum is {minimum}")]
37    FileTooSmall { size: usize, minimum: usize },
38
39    /// CRC32C checksum mismatch for manifest.
40    #[error("manifest CRC32C mismatch: expected {expected:#010x}, got {actual:#010x}")]
41    ManifestChecksumMismatch { expected: u32, actual: u32 },
42
43    /// CRC32C checksum mismatch for footer payload.
44    #[error("footer checksum mismatch")]
45    FooterChecksumMismatch,
46
47    #[error("page index checksum mismatch")]
48    PageIndexChecksumMismatch,
49
50    /// Failed to decode protobuf manifest.
51    #[error("failed to decode manifest: {0}")]
52    ManifestDecode(#[from] prost::DecodeError),
53
54    /// Invalid offset or length in manifest.
55    #[error("invalid payload bounds: offset {offset}, length {length}, file size {file_size}")]
56    InvalidPayloadBounds {
57        offset: u64,
58        length: u64,
59        file_size: u64,
60    },
61
62    /// Invalid format (JSON parsing, etc).
63    #[error("invalid format: {0}")]
64    InvalidFormat(String),
65
66    /// Compression or decompression error.
67    #[error("compression error: {0}")]
68    CompressionError(String),
69
70    /// Bundle-specific errors.
71    #[error("invalid bundle magic: expected PRXB, got {0:?}")]
72    InvalidBundleMagic([u8; 4]),
73
74    /// Invalid Parquet file magic bytes.
75    #[error("invalid Parquet magic bytes (expected PAR1, got {0:?})")]
76    InvalidParquetMagic([u8; 4]),
77
78    /// Parquet footer length exceeds file size.
79    #[error("Parquet footer length {footer_len} exceeds file size {file_size}")]
80    InvalidParquetFooterLength { footer_len: u64, file_size: u64 },
81
82    /// I/O error (e.g., reading a file from disk).
83    #[error("I/O error: {0}")]
84    Io(#[from] std::io::Error),
85}