##// END OF EJS Templates
extensions: make `hg nonexistent` not crash with PyOxidizer...
extensions: make `hg nonexistent` not crash with PyOxidizer When running `hg nonexistent`, we try to look for extensions that provide that command. We do that by looking for files in the `hgext.__file__` directory. However, PyOxidizer doesn't provide a `__file__`, so we crash when running with PyOxidizer. We should be able to look for the command in built-in extensions, but we seem to already have code for skipping the scan when running in a frozen binary, so I just modified that code instead. By the way, it also seems like we should be able to search for extensions in the `hgext3rd` module, but we don't do that yet either (before or after this patch). Differential Revision: https://phab.mercurial-scm.org/D8750

File last commit:

r45570:afecc7f7 default
r45665:5d09a120 default
Show More
error.rs
60 lines | 1.6 KiB | application/rls-services+xml | RustLexer
use crate::exitcode;
use crate::ui::UiError;
use std::convert::From;
/// The kind of command error
#[derive(Debug, PartialEq)]
pub enum CommandErrorKind {
/// The command finished without error
Ok,
/// The root of the repository cannot be found
RootNotFound,
/// The current directory cannot be found
CurrentDirNotFound,
/// The standard output stream cannot be written to
StdoutError,
/// The standard error stream cannot be written to
StderrError,
}
impl CommandErrorKind {
pub fn get_exit_code(&self) -> exitcode::ExitCode {
match self {
CommandErrorKind::Ok => exitcode::OK,
CommandErrorKind::RootNotFound => exitcode::ABORT,
CommandErrorKind::CurrentDirNotFound => exitcode::ABORT,
CommandErrorKind::StdoutError => exitcode::ABORT,
CommandErrorKind::StderrError => exitcode::ABORT,
}
}
}
/// The error type for the Command trait
#[derive(Debug, PartialEq)]
pub struct CommandError {
pub kind: CommandErrorKind,
}
impl CommandError {
/// Exist the process with the corresponding exit code.
pub fn exit(&self) -> () {
std::process::exit(self.kind.get_exit_code())
}
}
impl From<CommandErrorKind> for CommandError {
fn from(kind: CommandErrorKind) -> Self {
CommandError { kind }
}
}
impl From<UiError> for CommandError {
fn from(error: UiError) -> Self {
CommandError {
kind: match error {
UiError::StdoutError(_) => CommandErrorKind::StdoutError,
UiError::StderrError(_) => CommandErrorKind::StderrError,
},
}
}
}