equal
deleted
inserted
replaced
6 IoError { |
6 IoError { |
7 error: std::io::Error, |
7 error: std::io::Error, |
8 context: IoErrorContext, |
8 context: IoErrorContext, |
9 }, |
9 }, |
10 |
10 |
11 /// A file under `.hg/` normally only written by Mercurial |
11 /// A file under `.hg/` normally only written by Mercurial is not in the |
|
12 /// expected format. This indicates a bug in Mercurial, filesystem |
|
13 /// corruption, or hardware failure. |
12 /// |
14 /// |
13 /// The given string is a short explanation for users, not intended to be |
15 /// The given string is a short explanation for users, not intended to be |
14 /// machine-readable. |
16 /// machine-readable. |
15 CorruptedRepository(String), |
17 CorruptedRepository(String), |
16 |
18 |
19 /// implementation may or may not work. |
21 /// implementation may or may not work. |
20 /// |
22 /// |
21 /// The given string is a short explanation for users, not intended to be |
23 /// The given string is a short explanation for users, not intended to be |
22 /// machine-readable. |
24 /// machine-readable. |
23 UnsupportedFeature(String), |
25 UnsupportedFeature(String), |
|
26 |
|
27 /// Operation cannot proceed for some other reason. |
|
28 /// |
|
29 /// The given string is a short explanation for users, not intended to be |
|
30 /// machine-readable. |
|
31 Abort(String), |
24 } |
32 } |
25 |
33 |
26 /// Details about where an I/O error happened |
34 /// Details about where an I/O error happened |
27 #[derive(Debug, derive_more::From)] |
35 #[derive(Debug, derive_more::From)] |
28 pub enum IoErrorContext { |
36 pub enum IoErrorContext { |
44 } |
52 } |
45 |
53 |
46 pub fn unsupported(explanation: impl Into<String>) -> Self { |
54 pub fn unsupported(explanation: impl Into<String>) -> Self { |
47 HgError::UnsupportedFeature(explanation.into()) |
55 HgError::UnsupportedFeature(explanation.into()) |
48 } |
56 } |
|
57 pub fn abort(explanation: impl Into<String>) -> Self { |
|
58 HgError::Abort(explanation.into()) |
|
59 } |
49 } |
60 } |
50 |
61 |
51 // TODO: use `DisplayBytes` instead to show non-Unicode filenames losslessly? |
62 // TODO: use `DisplayBytes` instead to show non-Unicode filenames losslessly? |
52 impl fmt::Display for HgError { |
63 impl fmt::Display for HgError { |
53 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
64 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
59 write!(f, "corrupted repository: {}", explanation) |
70 write!(f, "corrupted repository: {}", explanation) |
60 } |
71 } |
61 HgError::UnsupportedFeature(explanation) => { |
72 HgError::UnsupportedFeature(explanation) => { |
62 write!(f, "unsupported feature: {}", explanation) |
73 write!(f, "unsupported feature: {}", explanation) |
63 } |
74 } |
|
75 HgError::Abort(explanation) => explanation.fmt(f), |
64 } |
76 } |
65 } |
77 } |
66 } |
78 } |
67 |
79 |
68 // TODO: use `DisplayBytes` instead to show non-Unicode filenames losslessly? |
80 // TODO: use `DisplayBytes` instead to show non-Unicode filenames losslessly? |