1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//! Error types for `ripsync-core`. Library code returns [`Result`]; it never
//! panics on bad input.
use std::path::PathBuf;
/// Convenience alias for results produced by `ripsync-core`.
pub type Result<T> = std::result::Result<T, Error>;
/// Errors that can arise while planning or applying a sync.
#[derive(Debug, thiserror::Error)]
pub enum Error {
/// The run was cancelled cooperatively.
#[error("run cancelled")]
Cancelled,
/// An underlying I/O failure, annotated with the offending path.
#[error("I/O error at {path}: {source}")]
Io {
/// Path that triggered the error.
path: PathBuf,
/// The underlying I/O error.
source: std::io::Error,
},
/// A bare I/O failure with no associated path.
#[error(transparent)]
BareIo(#[from] std::io::Error),
/// A path escaped the destination root (containment violation).
#[error("path escapes destination root: {0}")]
Containment(PathBuf),
/// `--delete` was requested but the source is empty or unreadable.
#[error("refusing to mirror deletions: source is empty or unreadable ({0})")]
EmptySource(PathBuf),
/// An exclude/glob pattern failed to compile.
#[error("invalid exclude pattern: {0}")]
Pattern(String),
/// An include/exclude/files-from filter was invalid.
#[error("filter error: {0}")]
Filter(String),
/// A delta could not be applied to the supplied basis.
#[error("delta apply failed: {0}")]
DeltaApply(String),
/// The remote-sync wire protocol was violated (bad frame, version mismatch,
/// unexpected message, oversized frame).
#[error("protocol error: {0}")]
Protocol(String),
/// Verification found one or more mismatches.
#[error("verification failed with {0} mismatch(es)")]
Verification(usize),
}
impl Error {
/// Wrap an [`std::io::Error`] together with the path that produced it.
#[must_use]
pub fn io(path: impl Into<PathBuf>, source: std::io::Error) -> Self {
Error::Io {
path: path.into(),
source,
}
}
}