equal
deleted
inserted
replaced
24 } |
24 } |
25 |
25 |
26 /// Details about where an I/O error happened |
26 /// Details about where an I/O error happened |
27 #[derive(Debug, derive_more::From)] |
27 #[derive(Debug, derive_more::From)] |
28 pub enum IoErrorContext { |
28 pub enum IoErrorContext { |
29 /// A filesystem operation returned `std::io::Error` |
29 /// A filesystem operation for the given file |
30 #[from] |
30 #[from] |
31 File(std::path::PathBuf), |
31 File(std::path::PathBuf), |
32 /// `std::env::current_dir` returned `std::io::Error` |
32 /// `std::env::current_dir` |
33 CurrentDir, |
33 CurrentDir, |
|
34 /// `std::env::current_exe` |
|
35 CurrentExe, |
34 } |
36 } |
35 |
37 |
36 impl HgError { |
38 impl HgError { |
37 pub fn corrupted(explanation: impl Into<String>) -> Self { |
39 pub fn corrupted(explanation: impl Into<String>) -> Self { |
38 // TODO: capture a backtrace here and keep it in the error value |
40 // TODO: capture a backtrace here and keep it in the error value |
67 impl fmt::Display for IoErrorContext { |
69 impl fmt::Display for IoErrorContext { |
68 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
70 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
69 match self { |
71 match self { |
70 IoErrorContext::File(path) => path.display().fmt(f), |
72 IoErrorContext::File(path) => path.display().fmt(f), |
71 IoErrorContext::CurrentDir => f.write_str("current directory"), |
73 IoErrorContext::CurrentDir => f.write_str("current directory"), |
|
74 IoErrorContext::CurrentExe => f.write_str("current executable"), |
72 } |
75 } |
73 } |
76 } |
74 } |
77 } |
75 |
78 |
76 pub trait IoResultExt<T> { |
79 pub trait IoResultExt<T> { |