rust/rhg/src/error.rs
author Simon Sapin <simon.sapin@octobus.net>
Wed, 03 Mar 2021 19:47:48 +0100
changeset 46731 3d692e724d06
parent 46666 33f2d56acc73
child 46735 12d59eec7f1d
permissions -rw-r--r--
rhg: Align config file parse error formatting with Python Differences can cause tests to fail Differential Revision: https://phab.mercurial-scm.org/D10110
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
46436
252d1bdba33d rhg: replace `map_*_error` functions with `From` impls
Simon Sapin <simon.sapin@octobus.net>
parents: 46435
diff changeset
     1
use crate::ui::utf8_to_local;
45049
513b3ef277a3 rhg: add RootCommand using hg-core FindRoot operation to prepare `hg root`
Antoine Cezar <antoine.cezar@octobus.net>
parents: 44982
diff changeset
     2
use crate::ui::UiError;
46593
5ce2aa7c2ad5 rhg: Move `Repo` object creation into `main()`
Simon Sapin <simon.sapin@octobus.net>
parents: 46591
diff changeset
     3
use crate::NoRepoInCwdError;
46446
1dcd9c9975ed rust: Fold find_root and check_requirements into Repo::find
Simon Sapin <simon.sapin@octobus.net>
parents: 46445
diff changeset
     4
use format_bytes::format_bytes;
46484
a6e4e4650bac rhg: Parse system and user configuration at program start
Simon Sapin <simon.sapin@octobus.net>
parents: 46446
diff changeset
     5
use hg::config::{ConfigError, ConfigParseError};
46446
1dcd9c9975ed rust: Fold find_root and check_requirements into Repo::find
Simon Sapin <simon.sapin@octobus.net>
parents: 46445
diff changeset
     6
use hg::errors::HgError;
46486
d7685105e504 rhg: Parse per-repository configuration
Simon Sapin <simon.sapin@octobus.net>
parents: 46484
diff changeset
     7
use hg::repo::RepoError;
46437
b274aa2f20fd rust: remove three enums that were identical to `RevlogError`
Simon Sapin <simon.sapin@octobus.net>
parents: 46436
diff changeset
     8
use hg::revlog::revlog::RevlogError;
46446
1dcd9c9975ed rust: Fold find_root and check_requirements into Repo::find
Simon Sapin <simon.sapin@octobus.net>
parents: 46445
diff changeset
     9
use hg::utils::files::get_bytes_from_path;
45049
513b3ef277a3 rhg: add RootCommand using hg-core FindRoot operation to prepare `hg root`
Antoine Cezar <antoine.cezar@octobus.net>
parents: 44982
diff changeset
    10
use std::convert::From;
513b3ef277a3 rhg: add RootCommand using hg-core FindRoot operation to prepare `hg root`
Antoine Cezar <antoine.cezar@octobus.net>
parents: 44982
diff changeset
    11
513b3ef277a3 rhg: add RootCommand using hg-core FindRoot operation to prepare `hg root`
Antoine Cezar <antoine.cezar@octobus.net>
parents: 44982
diff changeset
    12
/// The kind of command error
46445
ca3f73cc3cf4 rhg: Simplify CommandError based on its use
Simon Sapin <simon.sapin@octobus.net>
parents: 46443
diff changeset
    13
#[derive(Debug)]
46434
3e2d539d0d1a rust: remove `FooError` structs with only `kind: FooErrorKind` enum field
Simon Sapin <simon.sapin@octobus.net>
parents: 45984
diff changeset
    14
pub enum CommandError {
46445
ca3f73cc3cf4 rhg: Simplify CommandError based on its use
Simon Sapin <simon.sapin@octobus.net>
parents: 46443
diff changeset
    15
    /// Exit with an error message and "standard" failure exit code.
ca3f73cc3cf4 rhg: Simplify CommandError based on its use
Simon Sapin <simon.sapin@octobus.net>
parents: 46443
diff changeset
    16
    Abort { message: Vec<u8> },
ca3f73cc3cf4 rhg: Simplify CommandError based on its use
Simon Sapin <simon.sapin@octobus.net>
parents: 46443
diff changeset
    17
46666
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46593
diff changeset
    18
    /// Encountered something (such as a CLI argument, repository layout, …)
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46593
diff changeset
    19
    /// not supported by this version of `rhg`. Depending on configuration
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46593
diff changeset
    20
    /// `rhg` may attempt to silently fall back to Python-based `hg`, which
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46593
diff changeset
    21
    /// may or may not support this feature.
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46593
diff changeset
    22
    UnsupportedFeature { message: Vec<u8> },
45049
513b3ef277a3 rhg: add RootCommand using hg-core FindRoot operation to prepare `hg root`
Antoine Cezar <antoine.cezar@octobus.net>
parents: 44982
diff changeset
    23
}
513b3ef277a3 rhg: add RootCommand using hg-core FindRoot operation to prepare `hg root`
Antoine Cezar <antoine.cezar@octobus.net>
parents: 44982
diff changeset
    24
46434
3e2d539d0d1a rust: remove `FooError` structs with only `kind: FooErrorKind` enum field
Simon Sapin <simon.sapin@octobus.net>
parents: 45984
diff changeset
    25
impl CommandError {
46445
ca3f73cc3cf4 rhg: Simplify CommandError based on its use
Simon Sapin <simon.sapin@octobus.net>
parents: 46443
diff changeset
    26
    pub fn abort(message: impl AsRef<str>) -> Self {
ca3f73cc3cf4 rhg: Simplify CommandError based on its use
Simon Sapin <simon.sapin@octobus.net>
parents: 46443
diff changeset
    27
        CommandError::Abort {
ca3f73cc3cf4 rhg: Simplify CommandError based on its use
Simon Sapin <simon.sapin@octobus.net>
parents: 46443
diff changeset
    28
            // TODO: bytes-based (instead of Unicode-based) formatting
ca3f73cc3cf4 rhg: Simplify CommandError based on its use
Simon Sapin <simon.sapin@octobus.net>
parents: 46443
diff changeset
    29
            // of error messages to handle non-UTF-8 filenames etc:
ca3f73cc3cf4 rhg: Simplify CommandError based on its use
Simon Sapin <simon.sapin@octobus.net>
parents: 46443
diff changeset
    30
            // https://www.mercurial-scm.org/wiki/EncodingStrategy#Mixing_output
ca3f73cc3cf4 rhg: Simplify CommandError based on its use
Simon Sapin <simon.sapin@octobus.net>
parents: 46443
diff changeset
    31
            message: utf8_to_local(message.as_ref()).into(),
45049
513b3ef277a3 rhg: add RootCommand using hg-core FindRoot operation to prepare `hg root`
Antoine Cezar <antoine.cezar@octobus.net>
parents: 44982
diff changeset
    32
        }
513b3ef277a3 rhg: add RootCommand using hg-core FindRoot operation to prepare `hg root`
Antoine Cezar <antoine.cezar@octobus.net>
parents: 44982
diff changeset
    33
    }
46666
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46593
diff changeset
    34
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46593
diff changeset
    35
    pub fn unsupported(message: impl AsRef<str>) -> Self {
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46593
diff changeset
    36
        CommandError::UnsupportedFeature {
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46593
diff changeset
    37
            message: utf8_to_local(message.as_ref()).into(),
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46593
diff changeset
    38
        }
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46593
diff changeset
    39
    }
46445
ca3f73cc3cf4 rhg: Simplify CommandError based on its use
Simon Sapin <simon.sapin@octobus.net>
parents: 46443
diff changeset
    40
}
45361
47997afadf08 rhg: ask the error message from `CommandError`
Antoine Cezar <antoine.cezar@octobus.net>
parents: 45360
diff changeset
    41
46591
21d3b40b4c0e rhg: Remove error message on unsupported CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46503
diff changeset
    42
/// For now we don’t differenciate between invalid CLI args and valid for `hg`
21d3b40b4c0e rhg: Remove error message on unsupported CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46503
diff changeset
    43
/// but not supported yet by `rhg`.
21d3b40b4c0e rhg: Remove error message on unsupported CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46503
diff changeset
    44
impl From<clap::Error> for CommandError {
46666
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46593
diff changeset
    45
    fn from(error: clap::Error) -> Self {
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46593
diff changeset
    46
        CommandError::unsupported(error.to_string())
46591
21d3b40b4c0e rhg: Remove error message on unsupported CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46503
diff changeset
    47
    }
21d3b40b4c0e rhg: Remove error message on unsupported CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46503
diff changeset
    48
}
21d3b40b4c0e rhg: Remove error message on unsupported CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46503
diff changeset
    49
46445
ca3f73cc3cf4 rhg: Simplify CommandError based on its use
Simon Sapin <simon.sapin@octobus.net>
parents: 46443
diff changeset
    50
impl From<HgError> for CommandError {
ca3f73cc3cf4 rhg: Simplify CommandError based on its use
Simon Sapin <simon.sapin@octobus.net>
parents: 46443
diff changeset
    51
    fn from(error: HgError) -> Self {
ca3f73cc3cf4 rhg: Simplify CommandError based on its use
Simon Sapin <simon.sapin@octobus.net>
parents: 46443
diff changeset
    52
        match error {
46666
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46593
diff changeset
    53
            HgError::UnsupportedFeature(message) => {
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46593
diff changeset
    54
                CommandError::unsupported(message)
33f2d56acc73 rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents: 46593
diff changeset
    55
            }
46445
ca3f73cc3cf4 rhg: Simplify CommandError based on its use
Simon Sapin <simon.sapin@octobus.net>
parents: 46443
diff changeset
    56
            _ => CommandError::abort(error.to_string()),
45361
47997afadf08 rhg: ask the error message from `CommandError`
Antoine Cezar <antoine.cezar@octobus.net>
parents: 45360
diff changeset
    57
        }
47997afadf08 rhg: ask the error message from `CommandError`
Antoine Cezar <antoine.cezar@octobus.net>
parents: 45360
diff changeset
    58
    }
45049
513b3ef277a3 rhg: add RootCommand using hg-core FindRoot operation to prepare `hg root`
Antoine Cezar <antoine.cezar@octobus.net>
parents: 44982
diff changeset
    59
}
513b3ef277a3 rhg: add RootCommand using hg-core FindRoot operation to prepare `hg root`
Antoine Cezar <antoine.cezar@octobus.net>
parents: 44982
diff changeset
    60
513b3ef277a3 rhg: add RootCommand using hg-core FindRoot operation to prepare `hg root`
Antoine Cezar <antoine.cezar@octobus.net>
parents: 44982
diff changeset
    61
impl From<UiError> for CommandError {
46445
ca3f73cc3cf4 rhg: Simplify CommandError based on its use
Simon Sapin <simon.sapin@octobus.net>
parents: 46443
diff changeset
    62
    fn from(_error: UiError) -> Self {
ca3f73cc3cf4 rhg: Simplify CommandError based on its use
Simon Sapin <simon.sapin@octobus.net>
parents: 46443
diff changeset
    63
        // If we already failed writing to stdout or stderr,
ca3f73cc3cf4 rhg: Simplify CommandError based on its use
Simon Sapin <simon.sapin@octobus.net>
parents: 46443
diff changeset
    64
        // writing an error message to stderr about it would be likely to fail
ca3f73cc3cf4 rhg: Simplify CommandError based on its use
Simon Sapin <simon.sapin@octobus.net>
parents: 46443
diff changeset
    65
        // too.
ca3f73cc3cf4 rhg: Simplify CommandError based on its use
Simon Sapin <simon.sapin@octobus.net>
parents: 46443
diff changeset
    66
        CommandError::abort("")
45049
513b3ef277a3 rhg: add RootCommand using hg-core FindRoot operation to prepare `hg root`
Antoine Cezar <antoine.cezar@octobus.net>
parents: 44982
diff changeset
    67
    }
513b3ef277a3 rhg: add RootCommand using hg-core FindRoot operation to prepare `hg root`
Antoine Cezar <antoine.cezar@octobus.net>
parents: 44982
diff changeset
    68
}
45363
5dbf875b3275 rhg: simplify `FindRootError` handling
Antoine Cezar <antoine.cezar@octobus.net>
parents: 45361
diff changeset
    69
46486
d7685105e504 rhg: Parse per-repository configuration
Simon Sapin <simon.sapin@octobus.net>
parents: 46484
diff changeset
    70
impl From<RepoError> for CommandError {
d7685105e504 rhg: Parse per-repository configuration
Simon Sapin <simon.sapin@octobus.net>
parents: 46484
diff changeset
    71
    fn from(error: RepoError) -> Self {
46446
1dcd9c9975ed rust: Fold find_root and check_requirements into Repo::find
Simon Sapin <simon.sapin@octobus.net>
parents: 46445
diff changeset
    72
        match error {
46503
d8730ff51d5a rhg: Add support for -R and --repository command-line arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46499
diff changeset
    73
            RepoError::NotFound { at } => CommandError::Abort {
46446
1dcd9c9975ed rust: Fold find_root and check_requirements into Repo::find
Simon Sapin <simon.sapin@octobus.net>
parents: 46445
diff changeset
    74
                message: format_bytes!(
46593
5ce2aa7c2ad5 rhg: Move `Repo` object creation into `main()`
Simon Sapin <simon.sapin@octobus.net>
parents: 46591
diff changeset
    75
                    b"repository {} not found",
46503
d8730ff51d5a rhg: Add support for -R and --repository command-line arguments
Simon Sapin <simon.sapin@octobus.net>
parents: 46499
diff changeset
    76
                    get_bytes_from_path(at)
46446
1dcd9c9975ed rust: Fold find_root and check_requirements into Repo::find
Simon Sapin <simon.sapin@octobus.net>
parents: 46445
diff changeset
    77
                ),
1dcd9c9975ed rust: Fold find_root and check_requirements into Repo::find
Simon Sapin <simon.sapin@octobus.net>
parents: 46445
diff changeset
    78
            },
46486
d7685105e504 rhg: Parse per-repository configuration
Simon Sapin <simon.sapin@octobus.net>
parents: 46484
diff changeset
    79
            RepoError::ConfigParseError(error) => error.into(),
d7685105e504 rhg: Parse per-repository configuration
Simon Sapin <simon.sapin@octobus.net>
parents: 46484
diff changeset
    80
            RepoError::Other(error) => error.into(),
45363
5dbf875b3275 rhg: simplify `FindRootError` handling
Antoine Cezar <antoine.cezar@octobus.net>
parents: 45361
diff changeset
    81
        }
5dbf875b3275 rhg: simplify `FindRootError` handling
Antoine Cezar <antoine.cezar@octobus.net>
parents: 45361
diff changeset
    82
    }
5dbf875b3275 rhg: simplify `FindRootError` handling
Antoine Cezar <antoine.cezar@octobus.net>
parents: 45361
diff changeset
    83
}
46436
252d1bdba33d rhg: replace `map_*_error` functions with `From` impls
Simon Sapin <simon.sapin@octobus.net>
parents: 46435
diff changeset
    84
46593
5ce2aa7c2ad5 rhg: Move `Repo` object creation into `main()`
Simon Sapin <simon.sapin@octobus.net>
parents: 46591
diff changeset
    85
impl<'a> From<&'a NoRepoInCwdError> for CommandError {
5ce2aa7c2ad5 rhg: Move `Repo` object creation into `main()`
Simon Sapin <simon.sapin@octobus.net>
parents: 46591
diff changeset
    86
    fn from(error: &'a NoRepoInCwdError) -> Self {
5ce2aa7c2ad5 rhg: Move `Repo` object creation into `main()`
Simon Sapin <simon.sapin@octobus.net>
parents: 46591
diff changeset
    87
        let NoRepoInCwdError { cwd } = error;
5ce2aa7c2ad5 rhg: Move `Repo` object creation into `main()`
Simon Sapin <simon.sapin@octobus.net>
parents: 46591
diff changeset
    88
        CommandError::Abort {
5ce2aa7c2ad5 rhg: Move `Repo` object creation into `main()`
Simon Sapin <simon.sapin@octobus.net>
parents: 46591
diff changeset
    89
            message: format_bytes!(
46731
3d692e724d06 rhg: Align config file parse error formatting with Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46666
diff changeset
    90
                b"abort: no repository found in '{}' (.hg not found)!",
46593
5ce2aa7c2ad5 rhg: Move `Repo` object creation into `main()`
Simon Sapin <simon.sapin@octobus.net>
parents: 46591
diff changeset
    91
                get_bytes_from_path(cwd)
5ce2aa7c2ad5 rhg: Move `Repo` object creation into `main()`
Simon Sapin <simon.sapin@octobus.net>
parents: 46591
diff changeset
    92
            ),
5ce2aa7c2ad5 rhg: Move `Repo` object creation into `main()`
Simon Sapin <simon.sapin@octobus.net>
parents: 46591
diff changeset
    93
        }
5ce2aa7c2ad5 rhg: Move `Repo` object creation into `main()`
Simon Sapin <simon.sapin@octobus.net>
parents: 46591
diff changeset
    94
    }
5ce2aa7c2ad5 rhg: Move `Repo` object creation into `main()`
Simon Sapin <simon.sapin@octobus.net>
parents: 46591
diff changeset
    95
}
5ce2aa7c2ad5 rhg: Move `Repo` object creation into `main()`
Simon Sapin <simon.sapin@octobus.net>
parents: 46591
diff changeset
    96
46484
a6e4e4650bac rhg: Parse system and user configuration at program start
Simon Sapin <simon.sapin@octobus.net>
parents: 46446
diff changeset
    97
impl From<ConfigError> for CommandError {
a6e4e4650bac rhg: Parse system and user configuration at program start
Simon Sapin <simon.sapin@octobus.net>
parents: 46446
diff changeset
    98
    fn from(error: ConfigError) -> Self {
a6e4e4650bac rhg: Parse system and user configuration at program start
Simon Sapin <simon.sapin@octobus.net>
parents: 46446
diff changeset
    99
        match error {
46486
d7685105e504 rhg: Parse per-repository configuration
Simon Sapin <simon.sapin@octobus.net>
parents: 46484
diff changeset
   100
            ConfigError::Parse(error) => error.into(),
46484
a6e4e4650bac rhg: Parse system and user configuration at program start
Simon Sapin <simon.sapin@octobus.net>
parents: 46446
diff changeset
   101
            ConfigError::Other(error) => error.into(),
a6e4e4650bac rhg: Parse system and user configuration at program start
Simon Sapin <simon.sapin@octobus.net>
parents: 46446
diff changeset
   102
        }
a6e4e4650bac rhg: Parse system and user configuration at program start
Simon Sapin <simon.sapin@octobus.net>
parents: 46446
diff changeset
   103
    }
a6e4e4650bac rhg: Parse system and user configuration at program start
Simon Sapin <simon.sapin@octobus.net>
parents: 46446
diff changeset
   104
}
a6e4e4650bac rhg: Parse system and user configuration at program start
Simon Sapin <simon.sapin@octobus.net>
parents: 46446
diff changeset
   105
46486
d7685105e504 rhg: Parse per-repository configuration
Simon Sapin <simon.sapin@octobus.net>
parents: 46484
diff changeset
   106
impl From<ConfigParseError> for CommandError {
d7685105e504 rhg: Parse per-repository configuration
Simon Sapin <simon.sapin@octobus.net>
parents: 46484
diff changeset
   107
    fn from(error: ConfigParseError) -> Self {
d7685105e504 rhg: Parse per-repository configuration
Simon Sapin <simon.sapin@octobus.net>
parents: 46484
diff changeset
   108
        let ConfigParseError {
d7685105e504 rhg: Parse per-repository configuration
Simon Sapin <simon.sapin@octobus.net>
parents: 46484
diff changeset
   109
            origin,
d7685105e504 rhg: Parse per-repository configuration
Simon Sapin <simon.sapin@octobus.net>
parents: 46484
diff changeset
   110
            line,
46731
3d692e724d06 rhg: Align config file parse error formatting with Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46666
diff changeset
   111
            message,
46486
d7685105e504 rhg: Parse per-repository configuration
Simon Sapin <simon.sapin@octobus.net>
parents: 46484
diff changeset
   112
        } = error;
d7685105e504 rhg: Parse per-repository configuration
Simon Sapin <simon.sapin@octobus.net>
parents: 46484
diff changeset
   113
        let line_message = if let Some(line_number) = line {
46731
3d692e724d06 rhg: Align config file parse error formatting with Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46666
diff changeset
   114
            format_bytes!(b":{}", line_number.to_string().into_bytes())
46486
d7685105e504 rhg: Parse per-repository configuration
Simon Sapin <simon.sapin@octobus.net>
parents: 46484
diff changeset
   115
        } else {
d7685105e504 rhg: Parse per-repository configuration
Simon Sapin <simon.sapin@octobus.net>
parents: 46484
diff changeset
   116
            Vec::new()
d7685105e504 rhg: Parse per-repository configuration
Simon Sapin <simon.sapin@octobus.net>
parents: 46484
diff changeset
   117
        };
d7685105e504 rhg: Parse per-repository configuration
Simon Sapin <simon.sapin@octobus.net>
parents: 46484
diff changeset
   118
        CommandError::Abort {
d7685105e504 rhg: Parse per-repository configuration
Simon Sapin <simon.sapin@octobus.net>
parents: 46484
diff changeset
   119
            message: format_bytes!(
46731
3d692e724d06 rhg: Align config file parse error formatting with Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46666
diff changeset
   120
                b"config error at {}{}: {}",
46499
eace48b4a786 rust: Use the DisplayBytes trait in config printing
Simon Sapin <simon.sapin@octobus.net>
parents: 46486
diff changeset
   121
                origin,
46486
d7685105e504 rhg: Parse per-repository configuration
Simon Sapin <simon.sapin@octobus.net>
parents: 46484
diff changeset
   122
                line_message,
46731
3d692e724d06 rhg: Align config file parse error formatting with Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46666
diff changeset
   123
                message
46486
d7685105e504 rhg: Parse per-repository configuration
Simon Sapin <simon.sapin@octobus.net>
parents: 46484
diff changeset
   124
            ),
d7685105e504 rhg: Parse per-repository configuration
Simon Sapin <simon.sapin@octobus.net>
parents: 46484
diff changeset
   125
        }
d7685105e504 rhg: Parse per-repository configuration
Simon Sapin <simon.sapin@octobus.net>
parents: 46484
diff changeset
   126
    }
d7685105e504 rhg: Parse per-repository configuration
Simon Sapin <simon.sapin@octobus.net>
parents: 46484
diff changeset
   127
}
d7685105e504 rhg: Parse per-repository configuration
Simon Sapin <simon.sapin@octobus.net>
parents: 46484
diff changeset
   128
46437
b274aa2f20fd rust: remove three enums that were identical to `RevlogError`
Simon Sapin <simon.sapin@octobus.net>
parents: 46436
diff changeset
   129
impl From<(RevlogError, &str)> for CommandError {
b274aa2f20fd rust: remove three enums that were identical to `RevlogError`
Simon Sapin <simon.sapin@octobus.net>
parents: 46436
diff changeset
   130
    fn from((err, rev): (RevlogError, &str)) -> CommandError {
46436
252d1bdba33d rhg: replace `map_*_error` functions with `From` impls
Simon Sapin <simon.sapin@octobus.net>
parents: 46435
diff changeset
   131
        match err {
46445
ca3f73cc3cf4 rhg: Simplify CommandError based on its use
Simon Sapin <simon.sapin@octobus.net>
parents: 46443
diff changeset
   132
            RevlogError::InvalidRevision => CommandError::abort(format!(
46731
3d692e724d06 rhg: Align config file parse error formatting with Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46666
diff changeset
   133
                "abort: invalid revision identifier: {}",
46445
ca3f73cc3cf4 rhg: Simplify CommandError based on its use
Simon Sapin <simon.sapin@octobus.net>
parents: 46443
diff changeset
   134
                rev
46436
252d1bdba33d rhg: replace `map_*_error` functions with `From` impls
Simon Sapin <simon.sapin@octobus.net>
parents: 46435
diff changeset
   135
            )),
46445
ca3f73cc3cf4 rhg: Simplify CommandError based on its use
Simon Sapin <simon.sapin@octobus.net>
parents: 46443
diff changeset
   136
            RevlogError::AmbiguousPrefix => CommandError::abort(format!(
46731
3d692e724d06 rhg: Align config file parse error formatting with Python
Simon Sapin <simon.sapin@octobus.net>
parents: 46666
diff changeset
   137
                "abort: ambiguous revision identifier: {}",
46445
ca3f73cc3cf4 rhg: Simplify CommandError based on its use
Simon Sapin <simon.sapin@octobus.net>
parents: 46443
diff changeset
   138
                rev
46436
252d1bdba33d rhg: replace `map_*_error` functions with `From` impls
Simon Sapin <simon.sapin@octobus.net>
parents: 46435
diff changeset
   139
            )),
46445
ca3f73cc3cf4 rhg: Simplify CommandError based on its use
Simon Sapin <simon.sapin@octobus.net>
parents: 46443
diff changeset
   140
            RevlogError::Other(error) => error.into(),
46436
252d1bdba33d rhg: replace `map_*_error` functions with `From` impls
Simon Sapin <simon.sapin@octobus.net>
parents: 46435
diff changeset
   141
        }
252d1bdba33d rhg: replace `map_*_error` functions with `From` impls
Simon Sapin <simon.sapin@octobus.net>
parents: 46435
diff changeset
   142
    }
252d1bdba33d rhg: replace `map_*_error` functions with `From` impls
Simon Sapin <simon.sapin@octobus.net>
parents: 46435
diff changeset
   143
}