webaves/warc/
mod.rs

1//! WARC file processing.
2pub mod extract;
3mod header;
4mod reader;
5mod writer;
6
7pub use header::*;
8pub use reader::*;
9pub use writer::*;
10
11use thiserror::Error;
12
13/// Errors during parsing or formatting of WARC files.
14#[derive(Error, Debug)]
15pub enum WARCError {
16    /// Not a recognized WARC file.
17    #[error("unknown format")]
18    UnknownFormat,
19
20    /// Header couldn't be parsed or formatted.
21    #[error("malformed header (at offset {offset})")]
22    MalformedHeader {
23        /// Number of bytes read from the (uncompressed) input stream.
24        offset: u64,
25        /// Source of the error.
26        #[source]
27        source: Option<Box<dyn std::error::Error + Send + Sync>>,
28    },
29
30    /// The length of the record body does not correspond with the value in the header.
31    #[error("wrong block length (at record ID {record_id}")]
32    WrongBlockLength {
33        /// ID of the record
34        record_id: String,
35    },
36
37    /// Field contained an invalid value.
38    #[error("invalid field value (with name {name}, at record ID {record_id})")]
39    InvalidFieldValue {
40        /// Name of the field.
41        name: String,
42        /// ID of the record.
43        record_id: String,
44        /// Source of the error.
45        #[source]
46        source: Option<Box<dyn std::error::Error + Send + Sync>>,
47    },
48
49    /// End of the record is malformed.
50    #[error("malformed footer (at offset {offset})")]
51    MalformedFooter {
52        /// Number of bytes read from the (uncompressed) input stream.
53        offset: u64,
54    },
55
56    /// IO error.
57    #[error(transparent)]
58    Io(#[from] std::io::Error),
59}