Debian Codegraph @

src/error.rs

raw symbols SCIP
1 // Copyright (c) 2021 Harry [Majored] [[email protected]]
2 // MIT License (https://github.com/Majored/rs-async-zip/blob/main/LICENSE)
3
4 //! A module which holds relevant error reporting structures/types.
5
6 use std::fmt::{Display, Formatter};
7 use thiserror::Error;
8
9 /// A Result type alias over ZipError to minimise repetition.
10 pub type Result<V> = std::result::Result<V, ZipError>;
11
12 #[derive(Debug, PartialEq, Eq)]
13 pub enum Zip64ErrorCase {
14 TooManyFiles,
15 LargeFile,
16 }
17
18 impl Display for Zip64ErrorCase {
19 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
20 match self {
21 Self::TooManyFiles => write!(f, "More than 65536 files in archive"),
22 Self::LargeFile => write!(f, "File is larger than 4 GiB"),
23 }
24 }
25 }
26
27 /// An enum of possible errors and their descriptions.
28 #[non_exhaustive]
29 #[derive(Debug, Error)]
30 pub enum ZipError {
31 #[error("feature not supported: '{0}'")]
32 FeatureNotSupported(&'static str),
33 #[error("compression not supported: {0}")]
34 CompressionNotSupported(u16),
35 #[error("host attribute compatibility not supported: {0}")]
36 AttributeCompatibilityNotSupported(u16),
37 #[error("attempted to read a ZIP64 file whilst on a 32-bit target")]
38 TargetZip64NotSupported,
39 #[error("attempted to write a ZIP file with force_no_zip64 when ZIP64 is needed: {0}")]
40 Zip64Needed(Zip64ErrorCase),
41 #[error("end of file has not been reached")]
42 EOFNotReached,
43 #[error("extra fields exceeded maximum size")]
44 ExtraFieldTooLarge,
45 #[error("comment exceeded maximum size")]
46 CommentTooLarge,
47 #[error("filename exceeded maximum size")]
48 FileNameTooLarge,
49 #[error("attempted to convert non-UTF8 bytes to a string/str")]
50 StringNotUtf8,
51
52 #[error("unable to locate the end of central directory record")]
53 UnableToLocateEOCDR,
54 #[error("extra field size was indicated to be {0} but only {1} bytes remain")]
55 InvalidExtraFieldHeader(u16, usize),
56 #[error("zip64 extended information field was incomplete")]
57 Zip64ExtendedFieldIncomplete,
58
59 #[error("an upstream reader returned an error: {0}")]
60 UpstreamReadError(#[from] std::io::Error),
61 #[error("a computed CRC32 value did not match the expected value")]
62 CRC32CheckError,
63 #[error("entry index was out of bounds")]
64 EntryIndexOutOfBounds,
65 #[error("Encountered an unexpected header (actual: {0:#x}, expected: {1:#x}).")]
66 UnexpectedHeaderError(u32, u32),
67
68 #[error("Info-ZIP Unicode Comment Extra Field was incomplete")]
69 InfoZipUnicodeCommentFieldIncomplete,
70 #[error("Info-ZIP Unicode Path Extra Field was incomplete")]
71 InfoZipUnicodePathFieldIncomplete,
72 }