work
[pspp] / rust / src / lib.rs
1 use std::io::Error as IoError;
2 use thiserror::Error as ThisError;
3
4 pub mod endian;
5 pub mod raw;
6 pub mod sack;
7
8 #[derive(ThisError, Debug)]
9 pub enum Error {
10     #[error("Not an SPSS system file")]
11     NotASystemFile,
12
13     #[error("Invalid magic number {0:?}")]
14     BadMagic([u8; 4]),
15
16     #[error("I/O error ({0})")]
17     Io(#[from] IoError),
18
19     #[error("Invalid SAV compression code {0}")]
20     InvalidSavCompression(u32),
21
22     #[error("Invalid ZSAV compression code {0}")]
23     InvalidZsavCompression(u32),
24
25     #[error("Variable record at offset {offset:#x} specifies width {width} not in valid range [-1,255).")]
26     BadVariableWidth { offset: u64, width: i32 },
27
28     #[error("Document record at offset {offset:#x} has document line count ({n}) greater than the maximum number {max}.")]
29     BadDocumentLength { offset: u64, n: u32, max: u32 },
30
31     #[error("At offset {offset:#x}, Unrecognized record type {rec_type}.")]
32     BadRecordType { offset: u64, rec_type: u32 },
33
34     #[error("At offset {offset:#x}, variable label code ({code}) is not 0 or 1.")]
35     BadVariableLabelCode { offset: u64, code: u32 },
36
37     #[error(
38         "At offset {offset:#x}, numeric missing value code ({code}) is not -3, -2, 0, 1, 2, or 3."
39     )]
40     BadNumericMissingValueCode { offset: u64, code: i32 },
41
42     #[error("At offset {offset:#x}, string missing value code ({code}) is not 0, 1, 2, or 3.")]
43     BadStringMissingValueCode { offset: u64, code: i32 },
44
45     #[error("At offset {offset:#x}, number of value labels ({n}) is greater than the maximum number {max}.")]
46     BadNumberOfValueLabels { offset: u64, n: u32, max: u32 },
47
48     #[error("At offset {offset:#x}, number of variables indexes ({n}) is greater than the maximum number ({max}).")]
49     BadNumberOfVarIndexes { offset: u64, n: u32, max: u32 },
50
51     #[error("At offset {offset:#x}, record type 7 subtype {subtype} is too large with element size {size} and {count} elements.")]
52     ExtensionRecordTooLarge {
53         offset: u64,
54         subtype: u32,
55         size: u32,
56         count: u32,
57     },
58
59     #[error("Unexpected end of file at offset {offset:#x}, {case_ofs} bytes into a {case_len}-byte case.")]
60     EofInCase {
61         offset: u64,
62         case_ofs: u64,
63         case_len: usize,
64     },
65
66     #[error(
67         "Unexpected end of file at offset {offset:#x}, {case_ofs} bytes into a compressed case."
68     )]
69     EofInCompressedCase { offset: u64, case_ofs: u64 },
70
71     #[error("Data ends at offset {offset:#x}, {case_ofs} bytes into a compressed case.")]
72     PartialCompressedCase { offset: u64, case_ofs: u64 },
73
74     #[error("At {case_ofs} bytes into compressed case starting at offset {offset:#x}, a string was found where a number was expected.")]
75     CompressedNumberExpected { offset: u64, case_ofs: u64 },
76
77     #[error("At {case_ofs} bytes into compressed case starting at offset {offset:#x}, a number was found where a string was expected.")]
78     CompressedStringExpected { offset: u64, case_ofs: u64 },
79
80     #[error("Block count {n_blocks} in ZLIB trailer at offset {offset:#x} differs from expected block count {expected_n_blocks} calculated from trailer length {ztrailer_len}.")]
81     BadZlibTrailerNBlocks {
82         offset: u64,
83         n_blocks: u32,
84         expected_n_blocks: u64,
85         ztrailer_len: u64,
86     },
87 }