Mercurial > hg
comparison rust/rhg/src/error.rs @ 45924:a2eda1ff22aa
requirements: move loading to hg-core and add parsing
No functional change, checking comes later.
Differential Revision: https://phab.mercurial-scm.org/D9398
author | Simon Sapin <simon-commits@exyr.org> |
---|---|
date | Tue, 24 Nov 2020 17:49:16 +0100 |
parents | ead435aa5294 |
children | 2ad2745e0be9 |
comparison
equal
deleted
inserted
replaced
45923:ead435aa5294 | 45924:a2eda1ff22aa |
---|---|
1 use crate::exitcode; | 1 use crate::exitcode; |
2 use crate::ui::UiError; | 2 use crate::ui::UiError; |
3 use hg::operations::{FindRootError, FindRootErrorKind}; | 3 use hg::operations::{FindRootError, FindRootErrorKind}; |
4 use hg::requirements::RequirementsError; | |
4 use hg::utils::files::get_bytes_from_path; | 5 use hg::utils::files::get_bytes_from_path; |
5 use std::convert::From; | 6 use std::convert::From; |
6 use std::path::PathBuf; | 7 use std::path::PathBuf; |
7 | 8 |
8 /// The kind of command error | 9 /// The kind of command error |
10 pub enum CommandErrorKind { | 11 pub enum CommandErrorKind { |
11 /// The root of the repository cannot be found | 12 /// The root of the repository cannot be found |
12 RootNotFound(PathBuf), | 13 RootNotFound(PathBuf), |
13 /// The current directory cannot be found | 14 /// The current directory cannot be found |
14 CurrentDirNotFound(std::io::Error), | 15 CurrentDirNotFound(std::io::Error), |
15 /// Error while reading or writing a file | 16 /// `.hg/requires` |
16 // TODO: add the file name/path? | 17 RequirementsError(RequirementsError), |
17 FileError(std::io::Error), | |
18 /// The standard output stream cannot be written to | 18 /// The standard output stream cannot be written to |
19 StdoutError, | 19 StdoutError, |
20 /// The standard error stream cannot be written to | 20 /// The standard error stream cannot be written to |
21 StderrError, | 21 StderrError, |
22 /// The command aborted | 22 /// The command aborted |
28 impl CommandErrorKind { | 28 impl CommandErrorKind { |
29 pub fn get_exit_code(&self) -> exitcode::ExitCode { | 29 pub fn get_exit_code(&self) -> exitcode::ExitCode { |
30 match self { | 30 match self { |
31 CommandErrorKind::RootNotFound(_) => exitcode::ABORT, | 31 CommandErrorKind::RootNotFound(_) => exitcode::ABORT, |
32 CommandErrorKind::CurrentDirNotFound(_) => exitcode::ABORT, | 32 CommandErrorKind::CurrentDirNotFound(_) => exitcode::ABORT, |
33 CommandErrorKind::FileError(_) => exitcode::ABORT, | 33 CommandErrorKind::RequirementsError(_) => exitcode::ABORT, |
34 CommandErrorKind::StdoutError => exitcode::ABORT, | 34 CommandErrorKind::StdoutError => exitcode::ABORT, |
35 CommandErrorKind::StderrError => exitcode::ABORT, | 35 CommandErrorKind::StderrError => exitcode::ABORT, |
36 CommandErrorKind::Abort(_) => exitcode::ABORT, | 36 CommandErrorKind::Abort(_) => exitcode::ABORT, |
37 CommandErrorKind::Unimplemented => exitcode::UNIMPLEMENTED_COMMAND, | 37 CommandErrorKind::Unimplemented => exitcode::UNIMPLEMENTED_COMMAND, |
38 } | 38 } |
59 b"abort: error getting current working directory: ", | 59 b"abort: error getting current working directory: ", |
60 e.to_string().as_bytes(), | 60 e.to_string().as_bytes(), |
61 b"\n", | 61 b"\n", |
62 ] | 62 ] |
63 .concat(), | 63 .concat(), |
64 ), | |
65 CommandErrorKind::RequirementsError( | |
66 RequirementsError::Corrupted, | |
67 ) => Some( | |
68 "abort: .hg/requires is corrupted\n".as_bytes().to_owned(), | |
64 ), | 69 ), |
65 CommandErrorKind::Abort(message) => message.to_owned(), | 70 CommandErrorKind::Abort(message) => message.to_owned(), |
66 _ => None, | 71 _ => None, |
67 } | 72 } |
68 } | 73 } |
113 kind: CommandErrorKind::CurrentDirNotFound(e), | 118 kind: CommandErrorKind::CurrentDirNotFound(e), |
114 }, | 119 }, |
115 } | 120 } |
116 } | 121 } |
117 } | 122 } |
123 | |
124 impl From<RequirementsError> for CommandError { | |
125 fn from(err: RequirementsError) -> Self { | |
126 CommandError { | |
127 kind: CommandErrorKind::RequirementsError(err), | |
128 } | |
129 } | |
130 } |