1use crate::MAX_DESCRIPTOR_SIZE;
7use std::io;
8use std::path::PathBuf;
9use thiserror::Error;
10
11#[derive(Debug, Error)]
13#[non_exhaustive]
14pub enum ParseError {
15 #[error("VMDK descriptor is not valid UTF-8")]
17 InvalidEncoding(#[from] std::str::Utf8Error),
18 #[error("VMDK descriptor is missing required field '{0}'")]
20 MissingField(&'static str),
21 #[error("invalid VMDK descriptor: {0}")]
23 Invalid(String),
24}
25
26#[derive(Debug, Error)]
28#[non_exhaustive]
29pub enum OpenError {
30 #[error("the requested VMDK does not support writable access")]
32 ReadWriteUnsupported,
33 #[error("failed to open VMDK descriptor '{}'", path.display())]
35 OpenDescriptor {
36 path: PathBuf,
38 #[source]
40 source: io::Error,
41 },
42 #[error("failed to read metadata for VMDK descriptor '{}'", path.display())]
44 ReadDescriptorMetadata {
45 path: PathBuf,
47 #[source]
49 source: io::Error,
50 },
51 #[error("VMDK descriptor '{}' is not a regular file", .0.display())]
53 DescriptorNotRegularFile(PathBuf),
54 #[error("VMDK descriptor is larger than {MAX_DESCRIPTOR_SIZE} bytes")]
56 DescriptorTooLarge,
57 #[error("failed to read VMDK descriptor '{}'", path.display())]
59 ReadDescriptor {
60 path: PathBuf,
62 #[source]
64 source: io::Error,
65 },
66 #[error(transparent)]
68 Parse(#[from] ParseError),
69 #[error("failed to open VMDK extent '{}'", path.display())]
71 OpenExtent {
72 path: PathBuf,
74 #[source]
76 source: io::Error,
77 },
78 #[error("failed to read metadata for VMDK source file {index}")]
80 ReadExtentMetadata {
81 index: usize,
83 #[source]
85 source: io::Error,
86 },
87 #[error("VMDK source file {0} is not a regular file")]
89 ExtentNotRegularFile(usize),
90 #[error("invalid VMDK extent map: {0}")]
92 InvalidExtentMap(String),
93}