lds_pack/error.rs
1//! Error type for pack creation, inspection, and restore.
2
3use std::path::PathBuf;
4
5use thiserror::Error;
6
7/// Errors produced by the pack module.
8#[derive(Debug, Error)]
9pub enum PackError {
10 /// An I/O error while reading the project or writing the archive.
11 #[error("pack I/O error: {0}")]
12 Io(#[from] std::io::Error),
13
14 /// The tree walk failed (permission denied, vanished directory, cycle).
15 #[error("pack walk error: {0}")]
16 Walk(#[from] walkdir::Error),
17
18 /// The given path is not a directory.
19 #[error("not a directory: {0}")]
20 NotADirectory(PathBuf),
21
22 /// A configured glob could not be compiled.
23 ///
24 /// Carries the offending pattern so a typo in `[pack]` points at itself
25 /// rather than silently matching nothing.
26 #[error("invalid pack pattern '{pattern}': {message}")]
27 BadPattern {
28 /// The pattern as written in configuration.
29 pattern: String,
30 /// Why it failed to compile.
31 message: String,
32 },
33
34 /// The manifest could not be serialized.
35 #[error("manifest serialize error: {0}")]
36 ManifestSerialize(#[from] toml::ser::Error),
37
38 /// The manifest could not be parsed.
39 #[error("manifest parse error: {0}")]
40 ManifestParse(#[from] toml::de::Error),
41
42 /// The archive did not begin with a `pack.toml` entry.
43 #[error("archive has no {name} entry — not an lds pack?", name = crate::manifest::MANIFEST_NAME)]
44 MissingManifest,
45
46 /// The archive was written by a newer pack format than this build reads.
47 #[error("pack format version {found} is newer than supported version {supported}")]
48 UnsupportedFormat {
49 /// Version recorded in the archive.
50 found: u32,
51 /// Highest version this build understands.
52 supported: u32,
53 },
54
55 /// The restore destination already exists and would be overwritten.
56 #[error("destination already exists: {0}")]
57 DestinationExists(PathBuf),
58}