1 use std::io::Error as IoError;
2 use thiserror::Error as ThisError;
11 #[derive(ThisError, Debug)]
13 #[error("Not an SPSS system file")]
16 #[error("Invalid magic number {0:?}")]
19 #[error("I/O error ({0})")]
22 #[error("Invalid SAV compression code {0}")]
23 InvalidSavCompression(u32),
25 #[error("Invalid ZSAV compression code {0}")]
26 InvalidZsavCompression(u32),
28 #[error("Variable record at offset {offset:#x} specifies width {width} not in valid range [-1,255).")]
29 BadVariableWidth { offset: u64, width: i32 },
31 #[error("Document record at offset {offset:#x} has document line count ({n}) greater than the maximum number {max}.")]
32 BadDocumentLength { offset: u64, n: u32, max: u32 },
34 #[error("At offset {offset:#x}, unrecognized record type {rec_type}.")]
35 BadRecordType { offset: u64, rec_type: u32 },
37 #[error("At offset {offset:#x}, variable label code ({code}) is not 0 or 1.")]
38 BadVariableLabelCode { offset: u64, code: u32 },
41 "At offset {offset:#x}, numeric missing value code ({code}) is not -3, -2, 0, 1, 2, or 3."
43 BadNumericMissingValueCode { offset: u64, code: i32 },
45 #[error("At offset {offset:#x}, string missing value code ({code}) is not 0, 1, 2, or 3.")]
46 BadStringMissingValueCode { offset: u64, code: i32 },
48 #[error("At offset {offset:#x}, number of value labels ({n}) is greater than the maximum number {max}.")]
49 BadNumberOfValueLabels { offset: u64, n: u32, max: u32 },
51 #[error("At offset {offset:#x}, number of variables indexes ({n}) is greater than the maximum number ({max}).")]
52 BadNumberOfVarIndexes { offset: u64, n: u32, max: u32 },
54 #[error("At offset {offset:#x}, record type 7 subtype {subtype} is too large with element size {size} and {count} elements.")]
55 ExtensionRecordTooLarge {
62 #[error("Unexpected end of file at offset {offset:#x}, {case_ofs} bytes into a {case_len}-byte case.")]
70 "Unexpected end of file at offset {offset:#x}, {case_ofs} bytes into a compressed case."
72 EofInCompressedCase { offset: u64, case_ofs: u64 },
74 #[error("Data ends at offset {offset:#x}, {case_ofs} bytes into a compressed case.")]
75 PartialCompressedCase { offset: u64, case_ofs: u64 },
77 #[error("At {case_ofs} bytes into compressed case starting at offset {offset:#x}, a string was found where a number was expected.")]
78 CompressedNumberExpected { offset: u64, case_ofs: u64 },
80 #[error("At {case_ofs} bytes into compressed case starting at offset {offset:#x}, a number was found where a string was expected.")]
81 CompressedStringExpected { offset: u64, case_ofs: u64 },
83 #[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}.")]
84 BadZlibTrailerNBlocks {
87 expected_n_blocks: u64,
91 #[error("At offset {offset:#x}, {record} has bad size {size} bytes instead of the expected {expected_size}.")]
92 BadRecordSize { offset: u64, record: String, size: u32, expected_size: u32 },
94 #[error("At offset {offset:#x}, {record} has bad count {count} instead of the expected {expected_count}.")]
95 BadRecordCount { offset: u64, record: String, count: u32, expected_count: u32 },
97 #[error("The encoding record at offset {offset:#x} contains an encoding name that is not valid UTF-8.")]
98 BadEncodingName { offset: u64 },
100 #[error("In long string missing values record starting at offset {record_offset:#x}, value length at offset {offset:#x} is {value_len} instead of the expected 8.")]
101 BadLongMissingValueLength { record_offset: u64, offset: u64, value_len: u32 },
103 #[error("This file has corrupted metadata written by a buggy version of PSPP. To ensure that other software can read it correctly, save a new copy of the file.")]
104 BadLongMissingValueFormat,
106 #[error("File creation date {creation_date} is not in the expected format \"DD MMM YY\" format. Using 01 Jan 1970.")]
107 InvalidCreationDate { creation_date: String },
109 #[error("File creation time {creation_time} is not in the expected format \"HH:MM:SS\" format. Using midnight.")]
110 InvalidCreationTime { creation_time: String },
112 #[error("Details TBD")]
116 #[derive(Copy, Clone, Debug)]
117 pub enum Compression {
122 #[derive(Clone, Debug)]
123 pub enum CategoryLabels {