Mercurial > hg
annotate rust/rhg/src/error.rs @ 52304:04b9a56c2d25
rust-lib: only export very common types to the top of the crate
This was done very early in the Rust project's lifecycle and I had very little
Rust experience. Let's keep the `DirstateParents` since they'll pop up in
all higher-level code and make the rest more explicit imports to make the
imports less confusing and the lib less cluttered.
author | Raphaël Gomès <rgomes@octobus.net> |
---|---|
date | Mon, 04 Nov 2024 11:13:05 +0100 |
parents | db065b33fa56 |
children | 79e8118cd846 |
rev | line source |
---|---|
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; |
46797
bcdcb4423ae3
rhg: Add more conversions between error types
Simon Sapin <simon.sapin@octobus.net>
parents:
46744
diff
changeset
|
5 use hg::config::{ConfigError, ConfigParseError, ConfigValueParseError}; |
52302
db065b33fa56
rust-dirstate: merge `dirstate_tree` module into `dirstate`
Raphaël Gomès <rgomes@octobus.net>
parents:
52045
diff
changeset
|
6 use hg::dirstate::on_disk::DirstateV2ParseError; |
52304
04b9a56c2d25
rust-lib: only export very common types to the top of the crate
Raphaël Gomès <rgomes@octobus.net>
parents:
52302
diff
changeset
|
7 use hg::dirstate::status::StatusError; |
46446
1dcd9c9975ed
rust: Fold find_root and check_requirements into Repo::find
Simon Sapin <simon.sapin@octobus.net>
parents:
46445
diff
changeset
|
8 use hg::errors::HgError; |
47407
6e49769b7f97
rhg: add exit code to HgError::Abort()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
46821
diff
changeset
|
9 use hg::exit_codes; |
46486
d7685105e504
rhg: Parse per-repository configuration
Simon Sapin <simon.sapin@octobus.net>
parents:
46484
diff
changeset
|
10 use hg::repo::RepoError; |
49937
750409505286
rust-clippy: merge "revlog" module definition and struct implementation
Raphaël Gomès <rgomes@octobus.net>
parents:
49914
diff
changeset
|
11 use hg::revlog::RevlogError; |
49485
ffd4b1f1c9cb
rhg: add sparse support
Raphaël Gomès <rgomes@octobus.net>
parents:
49174
diff
changeset
|
12 use hg::sparse::SparseConfigError; |
46446
1dcd9c9975ed
rust: Fold find_root and check_requirements into Repo::find
Simon Sapin <simon.sapin@octobus.net>
parents:
46445
diff
changeset
|
13 use hg::utils::files::get_bytes_from_path; |
50866
c112cc9effdc
rhg: support "status FILE"
Spencer Baugh <sbaugh@janestreet.com>
parents:
49937
diff
changeset
|
14 use hg::utils::hg_path::HgPathError; |
52304
04b9a56c2d25
rust-lib: only export very common types to the top of the crate
Raphaël Gomès <rgomes@octobus.net>
parents:
52302
diff
changeset
|
15 use hg::{DirstateError, DirstateMapError, PatternError}; |
45049
513b3ef277a3
rhg: add RootCommand using hg-core FindRoot operation to prepare `hg root`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44982
diff
changeset
|
16 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
|
17 |
513b3ef277a3
rhg: add RootCommand using hg-core FindRoot operation to prepare `hg root`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44982
diff
changeset
|
18 /// The kind of command error |
46445
ca3f73cc3cf4
rhg: Simplify CommandError based on its use
Simon Sapin <simon.sapin@octobus.net>
parents:
46443
diff
changeset
|
19 #[derive(Debug)] |
46434
3e2d539d0d1a
rust: remove `FooError` structs with only `kind: FooErrorKind` enum field
Simon Sapin <simon.sapin@octobus.net>
parents:
45984
diff
changeset
|
20 pub enum CommandError { |
46445
ca3f73cc3cf4
rhg: Simplify CommandError based on its use
Simon Sapin <simon.sapin@octobus.net>
parents:
46443
diff
changeset
|
21 /// Exit with an error message and "standard" failure exit code. |
46820
821929d59e01
rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents:
46797
diff
changeset
|
22 Abort { |
821929d59e01
rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents:
46797
diff
changeset
|
23 message: Vec<u8>, |
47407
6e49769b7f97
rhg: add exit code to HgError::Abort()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
46821
diff
changeset
|
24 detailed_exit_code: exit_codes::ExitCode, |
49488
9f14126cfc4c
rust: add support for hints in error messages
Raphaël Gomès <rgomes@octobus.net>
parents:
49485
diff
changeset
|
25 hint: Option<Vec<u8>>, |
46820
821929d59e01
rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents:
46797
diff
changeset
|
26 }, |
46445
ca3f73cc3cf4
rhg: Simplify CommandError based on its use
Simon Sapin <simon.sapin@octobus.net>
parents:
46443
diff
changeset
|
27 |
46744
b1f2c2b336ec
rhg: `cat` command: print error messages for missing files
Simon Sapin <simon.sapin@octobus.net>
parents:
46735
diff
changeset
|
28 /// Exit with a failure exit code but no message. |
b1f2c2b336ec
rhg: `cat` command: print error messages for missing files
Simon Sapin <simon.sapin@octobus.net>
parents:
46735
diff
changeset
|
29 Unsuccessful, |
b1f2c2b336ec
rhg: `cat` command: print error messages for missing files
Simon Sapin <simon.sapin@octobus.net>
parents:
46735
diff
changeset
|
30 |
46666
33f2d56acc73
rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents:
46593
diff
changeset
|
31 /// 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
|
32 /// 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
|
33 /// `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
|
34 /// 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
|
35 UnsupportedFeature { message: Vec<u8> }, |
49149
006688e36e12
rhg: use `Command::exec` instead of `Command::status`
Raphaël Gomès <rgomes@octobus.net>
parents:
47674
diff
changeset
|
36 /// The fallback executable does not exist (or has some other problem if |
006688e36e12
rhg: use `Command::exec` instead of `Command::status`
Raphaël Gomès <rgomes@octobus.net>
parents:
47674
diff
changeset
|
37 /// we end up being more precise about broken fallbacks). |
006688e36e12
rhg: use `Command::exec` instead of `Command::status`
Raphaël Gomès <rgomes@octobus.net>
parents:
47674
diff
changeset
|
38 InvalidFallback { path: Vec<u8>, err: String }, |
45049
513b3ef277a3
rhg: add RootCommand using hg-core FindRoot operation to prepare `hg root`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44982
diff
changeset
|
39 } |
513b3ef277a3
rhg: add RootCommand using hg-core FindRoot operation to prepare `hg root`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44982
diff
changeset
|
40 |
46434
3e2d539d0d1a
rust: remove `FooError` structs with only `kind: FooErrorKind` enum field
Simon Sapin <simon.sapin@octobus.net>
parents:
45984
diff
changeset
|
41 impl CommandError { |
46445
ca3f73cc3cf4
rhg: Simplify CommandError based on its use
Simon Sapin <simon.sapin@octobus.net>
parents:
46443
diff
changeset
|
42 pub fn abort(message: impl AsRef<str>) -> Self { |
47407
6e49769b7f97
rhg: add exit code to HgError::Abort()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
46821
diff
changeset
|
43 CommandError::abort_with_exit_code(message, exit_codes::ABORT) |
46820
821929d59e01
rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents:
46797
diff
changeset
|
44 } |
821929d59e01
rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents:
46797
diff
changeset
|
45 |
821929d59e01
rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents:
46797
diff
changeset
|
46 pub fn abort_with_exit_code( |
821929d59e01
rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents:
46797
diff
changeset
|
47 message: impl AsRef<str>, |
47407
6e49769b7f97
rhg: add exit code to HgError::Abort()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
46821
diff
changeset
|
48 detailed_exit_code: exit_codes::ExitCode, |
46820
821929d59e01
rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents:
46797
diff
changeset
|
49 ) -> Self { |
46445
ca3f73cc3cf4
rhg: Simplify CommandError based on its use
Simon Sapin <simon.sapin@octobus.net>
parents:
46443
diff
changeset
|
50 CommandError::Abort { |
ca3f73cc3cf4
rhg: Simplify CommandError based on its use
Simon Sapin <simon.sapin@octobus.net>
parents:
46443
diff
changeset
|
51 // 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
|
52 // 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
|
53 // 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
|
54 message: utf8_to_local(message.as_ref()).into(), |
49914
58074252db3c
rust: run `cargo clippy`
Raphaël Gomès <rgomes@octobus.net>
parents:
49539
diff
changeset
|
55 detailed_exit_code, |
49488
9f14126cfc4c
rust: add support for hints in error messages
Raphaël Gomès <rgomes@octobus.net>
parents:
49485
diff
changeset
|
56 hint: None, |
9f14126cfc4c
rust: add support for hints in error messages
Raphaël Gomès <rgomes@octobus.net>
parents:
49485
diff
changeset
|
57 } |
9f14126cfc4c
rust: add support for hints in error messages
Raphaël Gomès <rgomes@octobus.net>
parents:
49485
diff
changeset
|
58 } |
9f14126cfc4c
rust: add support for hints in error messages
Raphaël Gomès <rgomes@octobus.net>
parents:
49485
diff
changeset
|
59 |
9f14126cfc4c
rust: add support for hints in error messages
Raphaël Gomès <rgomes@octobus.net>
parents:
49485
diff
changeset
|
60 pub fn abort_with_exit_code_and_hint( |
9f14126cfc4c
rust: add support for hints in error messages
Raphaël Gomès <rgomes@octobus.net>
parents:
49485
diff
changeset
|
61 message: impl AsRef<str>, |
9f14126cfc4c
rust: add support for hints in error messages
Raphaël Gomès <rgomes@octobus.net>
parents:
49485
diff
changeset
|
62 detailed_exit_code: exit_codes::ExitCode, |
9f14126cfc4c
rust: add support for hints in error messages
Raphaël Gomès <rgomes@octobus.net>
parents:
49485
diff
changeset
|
63 hint: Option<impl AsRef<str>>, |
9f14126cfc4c
rust: add support for hints in error messages
Raphaël Gomès <rgomes@octobus.net>
parents:
49485
diff
changeset
|
64 ) -> Self { |
9f14126cfc4c
rust: add support for hints in error messages
Raphaël Gomès <rgomes@octobus.net>
parents:
49485
diff
changeset
|
65 CommandError::Abort { |
9f14126cfc4c
rust: add support for hints in error messages
Raphaël Gomès <rgomes@octobus.net>
parents:
49485
diff
changeset
|
66 message: utf8_to_local(message.as_ref()).into(), |
9f14126cfc4c
rust: add support for hints in error messages
Raphaël Gomès <rgomes@octobus.net>
parents:
49485
diff
changeset
|
67 detailed_exit_code, |
9f14126cfc4c
rust: add support for hints in error messages
Raphaël Gomès <rgomes@octobus.net>
parents:
49485
diff
changeset
|
68 hint: hint.map(|h| utf8_to_local(h.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
|
69 } |
513b3ef277a3
rhg: add RootCommand using hg-core FindRoot operation to prepare `hg root`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44982
diff
changeset
|
70 } |
46666
33f2d56acc73
rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents:
46593
diff
changeset
|
71 |
49485
ffd4b1f1c9cb
rhg: add sparse support
Raphaël Gomès <rgomes@octobus.net>
parents:
49174
diff
changeset
|
72 pub fn abort_with_exit_code_bytes( |
ffd4b1f1c9cb
rhg: add sparse support
Raphaël Gomès <rgomes@octobus.net>
parents:
49174
diff
changeset
|
73 message: impl AsRef<[u8]>, |
ffd4b1f1c9cb
rhg: add sparse support
Raphaël Gomès <rgomes@octobus.net>
parents:
49174
diff
changeset
|
74 detailed_exit_code: exit_codes::ExitCode, |
ffd4b1f1c9cb
rhg: add sparse support
Raphaël Gomès <rgomes@octobus.net>
parents:
49174
diff
changeset
|
75 ) -> Self { |
ffd4b1f1c9cb
rhg: add sparse support
Raphaël Gomès <rgomes@octobus.net>
parents:
49174
diff
changeset
|
76 // TODO: use this everywhere it makes sense instead of the string |
ffd4b1f1c9cb
rhg: add sparse support
Raphaël Gomès <rgomes@octobus.net>
parents:
49174
diff
changeset
|
77 // version. |
ffd4b1f1c9cb
rhg: add sparse support
Raphaël Gomès <rgomes@octobus.net>
parents:
49174
diff
changeset
|
78 CommandError::Abort { |
ffd4b1f1c9cb
rhg: add sparse support
Raphaël Gomès <rgomes@octobus.net>
parents:
49174
diff
changeset
|
79 message: message.as_ref().into(), |
ffd4b1f1c9cb
rhg: add sparse support
Raphaël Gomès <rgomes@octobus.net>
parents:
49174
diff
changeset
|
80 detailed_exit_code, |
49488
9f14126cfc4c
rust: add support for hints in error messages
Raphaël Gomès <rgomes@octobus.net>
parents:
49485
diff
changeset
|
81 hint: None, |
49485
ffd4b1f1c9cb
rhg: add sparse support
Raphaël Gomès <rgomes@octobus.net>
parents:
49174
diff
changeset
|
82 } |
ffd4b1f1c9cb
rhg: add sparse support
Raphaël Gomès <rgomes@octobus.net>
parents:
49174
diff
changeset
|
83 } |
ffd4b1f1c9cb
rhg: add sparse support
Raphaël Gomès <rgomes@octobus.net>
parents:
49174
diff
changeset
|
84 |
46666
33f2d56acc73
rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents:
46593
diff
changeset
|
85 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
|
86 CommandError::UnsupportedFeature { |
33f2d56acc73
rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents:
46593
diff
changeset
|
87 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
|
88 } |
33f2d56acc73
rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents:
46593
diff
changeset
|
89 } |
46445
ca3f73cc3cf4
rhg: Simplify CommandError based on its use
Simon Sapin <simon.sapin@octobus.net>
parents:
46443
diff
changeset
|
90 } |
45361
47997afadf08
rhg: ask the error message from `CommandError`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45360
diff
changeset
|
91 |
46591
21d3b40b4c0e
rhg: Remove error message on unsupported CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents:
46503
diff
changeset
|
92 /// 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
|
93 /// 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
|
94 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
|
95 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
|
96 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
|
97 } |
21d3b40b4c0e
rhg: Remove error message on unsupported CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents:
46503
diff
changeset
|
98 } |
21d3b40b4c0e
rhg: Remove error message on unsupported CLI arguments
Simon Sapin <simon.sapin@octobus.net>
parents:
46503
diff
changeset
|
99 |
46445
ca3f73cc3cf4
rhg: Simplify CommandError based on its use
Simon Sapin <simon.sapin@octobus.net>
parents:
46443
diff
changeset
|
100 impl From<HgError> for CommandError { |
ca3f73cc3cf4
rhg: Simplify CommandError based on its use
Simon Sapin <simon.sapin@octobus.net>
parents:
46443
diff
changeset
|
101 fn from(error: HgError) -> Self { |
ca3f73cc3cf4
rhg: Simplify CommandError based on its use
Simon Sapin <simon.sapin@octobus.net>
parents:
46443
diff
changeset
|
102 match error { |
46666
33f2d56acc73
rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents:
46593
diff
changeset
|
103 HgError::UnsupportedFeature(message) => { |
33f2d56acc73
rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents:
46593
diff
changeset
|
104 CommandError::unsupported(message) |
33f2d56acc73
rhg: Add a `rhg.on-unsupported` configuration key
Simon Sapin <simon.sapin@octobus.net>
parents:
46593
diff
changeset
|
105 } |
49174
3f86ee422095
censor: make rhg fall back to python when encountering a censored node
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49149
diff
changeset
|
106 HgError::CensoredNodeError => { |
3f86ee422095
censor: make rhg fall back to python when encountering a censored node
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49149
diff
changeset
|
107 CommandError::unsupported("Encountered a censored node") |
3f86ee422095
censor: make rhg fall back to python when encountering a censored node
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49149
diff
changeset
|
108 } |
47408
7954ee2d7cf7
rhg: propogate error coming from HgError::Abort to CommandError
Pulkit Goyal <7895pulkit@gmail.com>
parents:
47407
diff
changeset
|
109 HgError::Abort { |
7954ee2d7cf7
rhg: propogate error coming from HgError::Abort to CommandError
Pulkit Goyal <7895pulkit@gmail.com>
parents:
47407
diff
changeset
|
110 message, |
7954ee2d7cf7
rhg: propogate error coming from HgError::Abort to CommandError
Pulkit Goyal <7895pulkit@gmail.com>
parents:
47407
diff
changeset
|
111 detailed_exit_code, |
49488
9f14126cfc4c
rust: add support for hints in error messages
Raphaël Gomès <rgomes@octobus.net>
parents:
49485
diff
changeset
|
112 hint, |
9f14126cfc4c
rust: add support for hints in error messages
Raphaël Gomès <rgomes@octobus.net>
parents:
49485
diff
changeset
|
113 } => CommandError::abort_with_exit_code_and_hint( |
9f14126cfc4c
rust: add support for hints in error messages
Raphaël Gomès <rgomes@octobus.net>
parents:
49485
diff
changeset
|
114 message, |
9f14126cfc4c
rust: add support for hints in error messages
Raphaël Gomès <rgomes@octobus.net>
parents:
49485
diff
changeset
|
115 detailed_exit_code, |
9f14126cfc4c
rust: add support for hints in error messages
Raphaël Gomès <rgomes@octobus.net>
parents:
49485
diff
changeset
|
116 hint, |
9f14126cfc4c
rust: add support for hints in error messages
Raphaël Gomès <rgomes@octobus.net>
parents:
49485
diff
changeset
|
117 ), |
46445
ca3f73cc3cf4
rhg: Simplify CommandError based on its use
Simon Sapin <simon.sapin@octobus.net>
parents:
46443
diff
changeset
|
118 _ => CommandError::abort(error.to_string()), |
45361
47997afadf08
rhg: ask the error message from `CommandError`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45360
diff
changeset
|
119 } |
47997afadf08
rhg: ask the error message from `CommandError`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45360
diff
changeset
|
120 } |
45049
513b3ef277a3
rhg: add RootCommand using hg-core FindRoot operation to prepare `hg root`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44982
diff
changeset
|
121 } |
513b3ef277a3
rhg: add RootCommand using hg-core FindRoot operation to prepare `hg root`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44982
diff
changeset
|
122 |
46797
bcdcb4423ae3
rhg: Add more conversions between error types
Simon Sapin <simon.sapin@octobus.net>
parents:
46744
diff
changeset
|
123 impl From<ConfigValueParseError> for CommandError { |
bcdcb4423ae3
rhg: Add more conversions between error types
Simon Sapin <simon.sapin@octobus.net>
parents:
46744
diff
changeset
|
124 fn from(error: ConfigValueParseError) -> Self { |
46820
821929d59e01
rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents:
46797
diff
changeset
|
125 CommandError::abort_with_exit_code( |
821929d59e01
rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents:
46797
diff
changeset
|
126 error.to_string(), |
47407
6e49769b7f97
rhg: add exit code to HgError::Abort()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
46821
diff
changeset
|
127 exit_codes::CONFIG_ERROR_ABORT, |
46820
821929d59e01
rhg: add support for detailed exit code for ConfigParseError
Pulkit Goyal <7895pulkit@gmail.com>
parents:
46797
diff
changeset
|
128 ) |
46797
bcdcb4423ae3
rhg: Add more conversions between error types
Simon Sapin <simon.sapin@octobus.net>
parents:
46744
diff
changeset
|
129 } |
bcdcb4423ae3
rhg: Add more conversions between error types
Simon Sapin <simon.sapin@octobus.net>
parents:
46744
diff
changeset
|
130 } |
bcdcb4423ae3
rhg: Add more conversions between error types
Simon Sapin <simon.sapin@octobus.net>
parents:
46744
diff
changeset
|
131 |
45049
513b3ef277a3
rhg: add RootCommand using hg-core FindRoot operation to prepare `hg root`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44982
diff
changeset
|
132 impl From<UiError> for CommandError { |
46445
ca3f73cc3cf4
rhg: Simplify CommandError based on its use
Simon Sapin <simon.sapin@octobus.net>
parents:
46443
diff
changeset
|
133 fn from(_error: UiError) -> Self { |
ca3f73cc3cf4
rhg: Simplify CommandError based on its use
Simon Sapin <simon.sapin@octobus.net>
parents:
46443
diff
changeset
|
134 // 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
|
135 // 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
|
136 // too. |
ca3f73cc3cf4
rhg: Simplify CommandError based on its use
Simon Sapin <simon.sapin@octobus.net>
parents:
46443
diff
changeset
|
137 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
|
138 } |
513b3ef277a3
rhg: add RootCommand using hg-core FindRoot operation to prepare `hg root`
Antoine Cezar <antoine.cezar@octobus.net>
parents:
44982
diff
changeset
|
139 } |
45363
5dbf875b3275
rhg: simplify `FindRootError` handling
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45361
diff
changeset
|
140 |
46486
d7685105e504
rhg: Parse per-repository configuration
Simon Sapin <simon.sapin@octobus.net>
parents:
46484
diff
changeset
|
141 impl From<RepoError> for CommandError { |
d7685105e504
rhg: Parse per-repository configuration
Simon Sapin <simon.sapin@octobus.net>
parents:
46484
diff
changeset
|
142 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
|
143 match error { |
49488
9f14126cfc4c
rust: add support for hints in error messages
Raphaël Gomès <rgomes@octobus.net>
parents:
49485
diff
changeset
|
144 RepoError::NotFound { at } => { |
9f14126cfc4c
rust: add support for hints in error messages
Raphaël Gomès <rgomes@octobus.net>
parents:
49485
diff
changeset
|
145 CommandError::abort_with_exit_code_bytes( |
9f14126cfc4c
rust: add support for hints in error messages
Raphaël Gomès <rgomes@octobus.net>
parents:
49485
diff
changeset
|
146 format_bytes!( |
9f14126cfc4c
rust: add support for hints in error messages
Raphaël Gomès <rgomes@octobus.net>
parents:
49485
diff
changeset
|
147 b"abort: repository {} not found", |
9f14126cfc4c
rust: add support for hints in error messages
Raphaël Gomès <rgomes@octobus.net>
parents:
49485
diff
changeset
|
148 get_bytes_from_path(at) |
9f14126cfc4c
rust: add support for hints in error messages
Raphaël Gomès <rgomes@octobus.net>
parents:
49485
diff
changeset
|
149 ), |
9f14126cfc4c
rust: add support for hints in error messages
Raphaël Gomès <rgomes@octobus.net>
parents:
49485
diff
changeset
|
150 exit_codes::ABORT, |
9f14126cfc4c
rust: add support for hints in error messages
Raphaël Gomès <rgomes@octobus.net>
parents:
49485
diff
changeset
|
151 ) |
9f14126cfc4c
rust: add support for hints in error messages
Raphaël Gomès <rgomes@octobus.net>
parents:
49485
diff
changeset
|
152 } |
46486
d7685105e504
rhg: Parse per-repository configuration
Simon Sapin <simon.sapin@octobus.net>
parents:
46484
diff
changeset
|
153 RepoError::ConfigParseError(error) => error.into(), |
d7685105e504
rhg: Parse per-repository configuration
Simon Sapin <simon.sapin@octobus.net>
parents:
46484
diff
changeset
|
154 RepoError::Other(error) => error.into(), |
45363
5dbf875b3275
rhg: simplify `FindRootError` handling
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45361
diff
changeset
|
155 } |
5dbf875b3275
rhg: simplify `FindRootError` handling
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45361
diff
changeset
|
156 } |
5dbf875b3275
rhg: simplify `FindRootError` handling
Antoine Cezar <antoine.cezar@octobus.net>
parents:
45361
diff
changeset
|
157 } |
46436
252d1bdba33d
rhg: replace `map_*_error` functions with `From` impls
Simon Sapin <simon.sapin@octobus.net>
parents:
46435
diff
changeset
|
158 |
46593
5ce2aa7c2ad5
rhg: Move `Repo` object creation into `main()`
Simon Sapin <simon.sapin@octobus.net>
parents:
46591
diff
changeset
|
159 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
|
160 fn from(error: &'a NoRepoInCwdError) -> Self { |
5ce2aa7c2ad5
rhg: Move `Repo` object creation into `main()`
Simon Sapin <simon.sapin@octobus.net>
parents:
46591
diff
changeset
|
161 let NoRepoInCwdError { cwd } = error; |
49488
9f14126cfc4c
rust: add support for hints in error messages
Raphaël Gomès <rgomes@octobus.net>
parents:
49485
diff
changeset
|
162 CommandError::abort_with_exit_code_bytes( |
9f14126cfc4c
rust: add support for hints in error messages
Raphaël Gomès <rgomes@octobus.net>
parents:
49485
diff
changeset
|
163 format_bytes!( |
46731
3d692e724d06
rhg: Align config file parse error formatting with Python
Simon Sapin <simon.sapin@octobus.net>
parents:
46666
diff
changeset
|
164 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
|
165 get_bytes_from_path(cwd) |
5ce2aa7c2ad5
rhg: Move `Repo` object creation into `main()`
Simon Sapin <simon.sapin@octobus.net>
parents:
46591
diff
changeset
|
166 ), |
49488
9f14126cfc4c
rust: add support for hints in error messages
Raphaël Gomès <rgomes@octobus.net>
parents:
49485
diff
changeset
|
167 exit_codes::ABORT, |
9f14126cfc4c
rust: add support for hints in error messages
Raphaël Gomès <rgomes@octobus.net>
parents:
49485
diff
changeset
|
168 ) |
46593
5ce2aa7c2ad5
rhg: Move `Repo` object creation into `main()`
Simon Sapin <simon.sapin@octobus.net>
parents:
46591
diff
changeset
|
169 } |
5ce2aa7c2ad5
rhg: Move `Repo` object creation into `main()`
Simon Sapin <simon.sapin@octobus.net>
parents:
46591
diff
changeset
|
170 } |
5ce2aa7c2ad5
rhg: Move `Repo` object creation into `main()`
Simon Sapin <simon.sapin@octobus.net>
parents:
46591
diff
changeset
|
171 |
46484
a6e4e4650bac
rhg: Parse system and user configuration at program start
Simon Sapin <simon.sapin@octobus.net>
parents:
46446
diff
changeset
|
172 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
|
173 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
|
174 match error { |
46486
d7685105e504
rhg: Parse per-repository configuration
Simon Sapin <simon.sapin@octobus.net>
parents:
46484
diff
changeset
|
175 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
|
176 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
|
177 } |
a6e4e4650bac
rhg: Parse system and user configuration at program start
Simon Sapin <simon.sapin@octobus.net>
parents:
46446
diff
changeset
|
178 } |
a6e4e4650bac
rhg: Parse system and user configuration at program start
Simon Sapin <simon.sapin@octobus.net>
parents:
46446
diff
changeset
|
179 } |
a6e4e4650bac
rhg: Parse system and user configuration at program start
Simon Sapin <simon.sapin@octobus.net>
parents:
46446
diff
changeset
|
180 |
46486
d7685105e504
rhg: Parse per-repository configuration
Simon Sapin <simon.sapin@octobus.net>
parents:
46484
diff
changeset
|
181 impl From<ConfigParseError> for CommandError { |
d7685105e504
rhg: Parse per-repository configuration
Simon Sapin <simon.sapin@octobus.net>
parents:
46484
diff
changeset
|
182 fn from(error: ConfigParseError) -> Self { |
d7685105e504
rhg: Parse per-repository configuration
Simon Sapin <simon.sapin@octobus.net>
parents:
46484
diff
changeset
|
183 let ConfigParseError { |
d7685105e504
rhg: Parse per-repository configuration
Simon Sapin <simon.sapin@octobus.net>
parents:
46484
diff
changeset
|
184 origin, |
d7685105e504
rhg: Parse per-repository configuration
Simon Sapin <simon.sapin@octobus.net>
parents:
46484
diff
changeset
|
185 line, |
46731
3d692e724d06
rhg: Align config file parse error formatting with Python
Simon Sapin <simon.sapin@octobus.net>
parents:
46666
diff
changeset
|
186 message, |
46486
d7685105e504
rhg: Parse per-repository configuration
Simon Sapin <simon.sapin@octobus.net>
parents:
46484
diff
changeset
|
187 } = error; |
d7685105e504
rhg: Parse per-repository configuration
Simon Sapin <simon.sapin@octobus.net>
parents:
46484
diff
changeset
|
188 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
|
189 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
|
190 } else { |
d7685105e504
rhg: Parse per-repository configuration
Simon Sapin <simon.sapin@octobus.net>
parents:
46484
diff
changeset
|
191 Vec::new() |
d7685105e504
rhg: Parse per-repository configuration
Simon Sapin <simon.sapin@octobus.net>
parents:
46484
diff
changeset
|
192 }; |
49488
9f14126cfc4c
rust: add support for hints in error messages
Raphaël Gomès <rgomes@octobus.net>
parents:
49485
diff
changeset
|
193 CommandError::abort_with_exit_code_bytes( |
9f14126cfc4c
rust: add support for hints in error messages
Raphaël Gomès <rgomes@octobus.net>
parents:
49485
diff
changeset
|
194 format_bytes!( |
46731
3d692e724d06
rhg: Align config file parse error formatting with Python
Simon Sapin <simon.sapin@octobus.net>
parents:
46666
diff
changeset
|
195 b"config error at {}{}: {}", |
46499
eace48b4a786
rust: Use the DisplayBytes trait in config printing
Simon Sapin <simon.sapin@octobus.net>
parents:
46486
diff
changeset
|
196 origin, |
46486
d7685105e504
rhg: Parse per-repository configuration
Simon Sapin <simon.sapin@octobus.net>
parents:
46484
diff
changeset
|
197 line_message, |
46731
3d692e724d06
rhg: Align config file parse error formatting with Python
Simon Sapin <simon.sapin@octobus.net>
parents:
46666
diff
changeset
|
198 message |
46486
d7685105e504
rhg: Parse per-repository configuration
Simon Sapin <simon.sapin@octobus.net>
parents:
46484
diff
changeset
|
199 ), |
49488
9f14126cfc4c
rust: add support for hints in error messages
Raphaël Gomès <rgomes@octobus.net>
parents:
49485
diff
changeset
|
200 exit_codes::CONFIG_ERROR_ABORT, |
9f14126cfc4c
rust: add support for hints in error messages
Raphaël Gomès <rgomes@octobus.net>
parents:
49485
diff
changeset
|
201 ) |
46486
d7685105e504
rhg: Parse per-repository configuration
Simon Sapin <simon.sapin@octobus.net>
parents:
46484
diff
changeset
|
202 } |
d7685105e504
rhg: Parse per-repository configuration
Simon Sapin <simon.sapin@octobus.net>
parents:
46484
diff
changeset
|
203 } |
d7685105e504
rhg: Parse per-repository configuration
Simon Sapin <simon.sapin@octobus.net>
parents:
46484
diff
changeset
|
204 |
46437
b274aa2f20fd
rust: remove three enums that were identical to `RevlogError`
Simon Sapin <simon.sapin@octobus.net>
parents:
46436
diff
changeset
|
205 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
|
206 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
|
207 match err { |
46821
e8ae91b1a63d
rhg: raise wdir specific error for `hg debugdata`
Pulkit Goyal <7895pulkit@gmail.com>
parents:
46820
diff
changeset
|
208 RevlogError::WDirUnsupported => CommandError::abort( |
e8ae91b1a63d
rhg: raise wdir specific error for `hg debugdata`
Pulkit Goyal <7895pulkit@gmail.com>
parents:
46820
diff
changeset
|
209 "abort: working directory revision cannot be specified", |
e8ae91b1a63d
rhg: raise wdir specific error for `hg debugdata`
Pulkit Goyal <7895pulkit@gmail.com>
parents:
46820
diff
changeset
|
210 ), |
52045
652149ed64f0
rust: improve `InvalidRevision` error message
Raphaël Gomès <rgomes@octobus.net>
parents:
50866
diff
changeset
|
211 RevlogError::InvalidRevision(r) => CommandError::abort(format!( |
46731
3d692e724d06
rhg: Align config file parse error formatting with Python
Simon Sapin <simon.sapin@octobus.net>
parents:
46666
diff
changeset
|
212 "abort: invalid revision identifier: {}", |
52045
652149ed64f0
rust: improve `InvalidRevision` error message
Raphaël Gomès <rgomes@octobus.net>
parents:
50866
diff
changeset
|
213 r |
46436
252d1bdba33d
rhg: replace `map_*_error` functions with `From` impls
Simon Sapin <simon.sapin@octobus.net>
parents:
46435
diff
changeset
|
214 )), |
46445
ca3f73cc3cf4
rhg: Simplify CommandError based on its use
Simon Sapin <simon.sapin@octobus.net>
parents:
46443
diff
changeset
|
215 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
|
216 "abort: ambiguous revision identifier: {}", |
46445
ca3f73cc3cf4
rhg: Simplify CommandError based on its use
Simon Sapin <simon.sapin@octobus.net>
parents:
46443
diff
changeset
|
217 rev |
46436
252d1bdba33d
rhg: replace `map_*_error` functions with `From` impls
Simon Sapin <simon.sapin@octobus.net>
parents:
46435
diff
changeset
|
218 )), |
46445
ca3f73cc3cf4
rhg: Simplify CommandError based on its use
Simon Sapin <simon.sapin@octobus.net>
parents:
46443
diff
changeset
|
219 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
|
220 } |
252d1bdba33d
rhg: replace `map_*_error` functions with `From` impls
Simon Sapin <simon.sapin@octobus.net>
parents:
46435
diff
changeset
|
221 } |
252d1bdba33d
rhg: replace `map_*_error` functions with `From` impls
Simon Sapin <simon.sapin@octobus.net>
parents:
46435
diff
changeset
|
222 } |
46797
bcdcb4423ae3
rhg: Add more conversions between error types
Simon Sapin <simon.sapin@octobus.net>
parents:
46744
diff
changeset
|
223 |
bcdcb4423ae3
rhg: Add more conversions between error types
Simon Sapin <simon.sapin@octobus.net>
parents:
46744
diff
changeset
|
224 impl From<StatusError> for CommandError { |
bcdcb4423ae3
rhg: Add more conversions between error types
Simon Sapin <simon.sapin@octobus.net>
parents:
46744
diff
changeset
|
225 fn from(error: StatusError) -> Self { |
49539
8076298b795a
rhg: fallback to slow path on invalid patterns in hgignore
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49489
diff
changeset
|
226 match error { |
8076298b795a
rhg: fallback to slow path on invalid patterns in hgignore
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49489
diff
changeset
|
227 StatusError::Pattern(_) => { |
8076298b795a
rhg: fallback to slow path on invalid patterns in hgignore
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49489
diff
changeset
|
228 CommandError::unsupported(format!("{}", error)) |
8076298b795a
rhg: fallback to slow path on invalid patterns in hgignore
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49489
diff
changeset
|
229 } |
8076298b795a
rhg: fallback to slow path on invalid patterns in hgignore
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49489
diff
changeset
|
230 _ => CommandError::abort(format!("{}", error)), |
8076298b795a
rhg: fallback to slow path on invalid patterns in hgignore
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
49489
diff
changeset
|
231 } |
46797
bcdcb4423ae3
rhg: Add more conversions between error types
Simon Sapin <simon.sapin@octobus.net>
parents:
46744
diff
changeset
|
232 } |
bcdcb4423ae3
rhg: Add more conversions between error types
Simon Sapin <simon.sapin@octobus.net>
parents:
46744
diff
changeset
|
233 } |
bcdcb4423ae3
rhg: Add more conversions between error types
Simon Sapin <simon.sapin@octobus.net>
parents:
46744
diff
changeset
|
234 |
50866
c112cc9effdc
rhg: support "status FILE"
Spencer Baugh <sbaugh@janestreet.com>
parents:
49937
diff
changeset
|
235 impl From<HgPathError> for CommandError { |
c112cc9effdc
rhg: support "status FILE"
Spencer Baugh <sbaugh@janestreet.com>
parents:
49937
diff
changeset
|
236 fn from(error: HgPathError) -> Self { |
c112cc9effdc
rhg: support "status FILE"
Spencer Baugh <sbaugh@janestreet.com>
parents:
49937
diff
changeset
|
237 CommandError::unsupported(format!("{}", error)) |
c112cc9effdc
rhg: support "status FILE"
Spencer Baugh <sbaugh@janestreet.com>
parents:
49937
diff
changeset
|
238 } |
c112cc9effdc
rhg: support "status FILE"
Spencer Baugh <sbaugh@janestreet.com>
parents:
49937
diff
changeset
|
239 } |
c112cc9effdc
rhg: support "status FILE"
Spencer Baugh <sbaugh@janestreet.com>
parents:
49937
diff
changeset
|
240 |
c112cc9effdc
rhg: support "status FILE"
Spencer Baugh <sbaugh@janestreet.com>
parents:
49937
diff
changeset
|
241 impl From<PatternError> for CommandError { |
c112cc9effdc
rhg: support "status FILE"
Spencer Baugh <sbaugh@janestreet.com>
parents:
49937
diff
changeset
|
242 fn from(error: PatternError) -> Self { |
c112cc9effdc
rhg: support "status FILE"
Spencer Baugh <sbaugh@janestreet.com>
parents:
49937
diff
changeset
|
243 CommandError::unsupported(format!("{}", error)) |
c112cc9effdc
rhg: support "status FILE"
Spencer Baugh <sbaugh@janestreet.com>
parents:
49937
diff
changeset
|
244 } |
c112cc9effdc
rhg: support "status FILE"
Spencer Baugh <sbaugh@janestreet.com>
parents:
49937
diff
changeset
|
245 } |
c112cc9effdc
rhg: support "status FILE"
Spencer Baugh <sbaugh@janestreet.com>
parents:
49937
diff
changeset
|
246 |
46797
bcdcb4423ae3
rhg: Add more conversions between error types
Simon Sapin <simon.sapin@octobus.net>
parents:
46744
diff
changeset
|
247 impl From<DirstateMapError> for CommandError { |
bcdcb4423ae3
rhg: Add more conversions between error types
Simon Sapin <simon.sapin@octobus.net>
parents:
46744
diff
changeset
|
248 fn from(error: DirstateMapError) -> Self { |
bcdcb4423ae3
rhg: Add more conversions between error types
Simon Sapin <simon.sapin@octobus.net>
parents:
46744
diff
changeset
|
249 CommandError::abort(format!("{}", error)) |
bcdcb4423ae3
rhg: Add more conversions between error types
Simon Sapin <simon.sapin@octobus.net>
parents:
46744
diff
changeset
|
250 } |
bcdcb4423ae3
rhg: Add more conversions between error types
Simon Sapin <simon.sapin@octobus.net>
parents:
46744
diff
changeset
|
251 } |
bcdcb4423ae3
rhg: Add more conversions between error types
Simon Sapin <simon.sapin@octobus.net>
parents:
46744
diff
changeset
|
252 |
bcdcb4423ae3
rhg: Add more conversions between error types
Simon Sapin <simon.sapin@octobus.net>
parents:
46744
diff
changeset
|
253 impl From<DirstateError> for CommandError { |
bcdcb4423ae3
rhg: Add more conversions between error types
Simon Sapin <simon.sapin@octobus.net>
parents:
46744
diff
changeset
|
254 fn from(error: DirstateError) -> Self { |
bcdcb4423ae3
rhg: Add more conversions between error types
Simon Sapin <simon.sapin@octobus.net>
parents:
46744
diff
changeset
|
255 match error { |
bcdcb4423ae3
rhg: Add more conversions between error types
Simon Sapin <simon.sapin@octobus.net>
parents:
46744
diff
changeset
|
256 DirstateError::Common(error) => error.into(), |
bcdcb4423ae3
rhg: Add more conversions between error types
Simon Sapin <simon.sapin@octobus.net>
parents:
46744
diff
changeset
|
257 DirstateError::Map(error) => error.into(), |
bcdcb4423ae3
rhg: Add more conversions between error types
Simon Sapin <simon.sapin@octobus.net>
parents:
46744
diff
changeset
|
258 } |
bcdcb4423ae3
rhg: Add more conversions between error types
Simon Sapin <simon.sapin@octobus.net>
parents:
46744
diff
changeset
|
259 } |
bcdcb4423ae3
rhg: Add more conversions between error types
Simon Sapin <simon.sapin@octobus.net>
parents:
46744
diff
changeset
|
260 } |
47674
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47408
diff
changeset
|
261 |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47408
diff
changeset
|
262 impl From<DirstateV2ParseError> for CommandError { |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47408
diff
changeset
|
263 fn from(error: DirstateV2ParseError) -> Self { |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47408
diff
changeset
|
264 HgError::from(error).into() |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47408
diff
changeset
|
265 } |
ff97e793ed36
dirstate-v2: Introduce a docket file
Simon Sapin <simon.sapin@octobus.net>
parents:
47408
diff
changeset
|
266 } |
49485
ffd4b1f1c9cb
rhg: add sparse support
Raphaël Gomès <rgomes@octobus.net>
parents:
49174
diff
changeset
|
267 |
ffd4b1f1c9cb
rhg: add sparse support
Raphaël Gomès <rgomes@octobus.net>
parents:
49174
diff
changeset
|
268 impl From<SparseConfigError> for CommandError { |
ffd4b1f1c9cb
rhg: add sparse support
Raphaël Gomès <rgomes@octobus.net>
parents:
49174
diff
changeset
|
269 fn from(e: SparseConfigError) -> Self { |
ffd4b1f1c9cb
rhg: add sparse support
Raphaël Gomès <rgomes@octobus.net>
parents:
49174
diff
changeset
|
270 match e { |
ffd4b1f1c9cb
rhg: add sparse support
Raphaël Gomès <rgomes@octobus.net>
parents:
49174
diff
changeset
|
271 SparseConfigError::IncludesAfterExcludes { context } => { |
ffd4b1f1c9cb
rhg: add sparse support
Raphaël Gomès <rgomes@octobus.net>
parents:
49174
diff
changeset
|
272 Self::abort_with_exit_code_bytes( |
ffd4b1f1c9cb
rhg: add sparse support
Raphaël Gomès <rgomes@octobus.net>
parents:
49174
diff
changeset
|
273 format_bytes!( |
ffd4b1f1c9cb
rhg: add sparse support
Raphaël Gomès <rgomes@octobus.net>
parents:
49174
diff
changeset
|
274 b"{} config cannot have includes after excludes", |
ffd4b1f1c9cb
rhg: add sparse support
Raphaël Gomès <rgomes@octobus.net>
parents:
49174
diff
changeset
|
275 context |
ffd4b1f1c9cb
rhg: add sparse support
Raphaël Gomès <rgomes@octobus.net>
parents:
49174
diff
changeset
|
276 ), |
ffd4b1f1c9cb
rhg: add sparse support
Raphaël Gomès <rgomes@octobus.net>
parents:
49174
diff
changeset
|
277 exit_codes::CONFIG_PARSE_ERROR_ABORT, |
ffd4b1f1c9cb
rhg: add sparse support
Raphaël Gomès <rgomes@octobus.net>
parents:
49174
diff
changeset
|
278 ) |
ffd4b1f1c9cb
rhg: add sparse support
Raphaël Gomès <rgomes@octobus.net>
parents:
49174
diff
changeset
|
279 } |
ffd4b1f1c9cb
rhg: add sparse support
Raphaël Gomès <rgomes@octobus.net>
parents:
49174
diff
changeset
|
280 SparseConfigError::EntryOutsideSection { context, line } => { |
ffd4b1f1c9cb
rhg: add sparse support
Raphaël Gomès <rgomes@octobus.net>
parents:
49174
diff
changeset
|
281 Self::abort_with_exit_code_bytes( |
ffd4b1f1c9cb
rhg: add sparse support
Raphaël Gomès <rgomes@octobus.net>
parents:
49174
diff
changeset
|
282 format_bytes!( |
ffd4b1f1c9cb
rhg: add sparse support
Raphaël Gomès <rgomes@octobus.net>
parents:
49174
diff
changeset
|
283 b"{} config entry outside of section: {}", |
ffd4b1f1c9cb
rhg: add sparse support
Raphaël Gomès <rgomes@octobus.net>
parents:
49174
diff
changeset
|
284 context, |
ffd4b1f1c9cb
rhg: add sparse support
Raphaël Gomès <rgomes@octobus.net>
parents:
49174
diff
changeset
|
285 &line, |
ffd4b1f1c9cb
rhg: add sparse support
Raphaël Gomès <rgomes@octobus.net>
parents:
49174
diff
changeset
|
286 ), |
ffd4b1f1c9cb
rhg: add sparse support
Raphaël Gomès <rgomes@octobus.net>
parents:
49174
diff
changeset
|
287 exit_codes::CONFIG_PARSE_ERROR_ABORT, |
ffd4b1f1c9cb
rhg: add sparse support
Raphaël Gomès <rgomes@octobus.net>
parents:
49174
diff
changeset
|
288 ) |
ffd4b1f1c9cb
rhg: add sparse support
Raphaël Gomès <rgomes@octobus.net>
parents:
49174
diff
changeset
|
289 } |
49489
7c93e38a0bbd
rhg-status: add support for narrow clones
Raphaël Gomès <rgomes@octobus.net>
parents:
49488
diff
changeset
|
290 SparseConfigError::InvalidNarrowPrefix(prefix) => { |
7c93e38a0bbd
rhg-status: add support for narrow clones
Raphaël Gomès <rgomes@octobus.net>
parents:
49488
diff
changeset
|
291 Self::abort_with_exit_code_bytes( |
7c93e38a0bbd
rhg-status: add support for narrow clones
Raphaël Gomès <rgomes@octobus.net>
parents:
49488
diff
changeset
|
292 format_bytes!( |
7c93e38a0bbd
rhg-status: add support for narrow clones
Raphaël Gomès <rgomes@octobus.net>
parents:
49488
diff
changeset
|
293 b"invalid prefix on narrow pattern: {}", |
7c93e38a0bbd
rhg-status: add support for narrow clones
Raphaël Gomès <rgomes@octobus.net>
parents:
49488
diff
changeset
|
294 &prefix |
7c93e38a0bbd
rhg-status: add support for narrow clones
Raphaël Gomès <rgomes@octobus.net>
parents:
49488
diff
changeset
|
295 ), |
7c93e38a0bbd
rhg-status: add support for narrow clones
Raphaël Gomès <rgomes@octobus.net>
parents:
49488
diff
changeset
|
296 exit_codes::ABORT, |
7c93e38a0bbd
rhg-status: add support for narrow clones
Raphaël Gomès <rgomes@octobus.net>
parents:
49488
diff
changeset
|
297 ) |
7c93e38a0bbd
rhg-status: add support for narrow clones
Raphaël Gomès <rgomes@octobus.net>
parents:
49488
diff
changeset
|
298 } |
7c93e38a0bbd
rhg-status: add support for narrow clones
Raphaël Gomès <rgomes@octobus.net>
parents:
49488
diff
changeset
|
299 SparseConfigError::IncludesInNarrow => Self::abort( |
7c93e38a0bbd
rhg-status: add support for narrow clones
Raphaël Gomès <rgomes@octobus.net>
parents:
49488
diff
changeset
|
300 "including other spec files using '%include' \ |
7c93e38a0bbd
rhg-status: add support for narrow clones
Raphaël Gomès <rgomes@octobus.net>
parents:
49488
diff
changeset
|
301 is not supported in narrowspec", |
7c93e38a0bbd
rhg-status: add support for narrow clones
Raphaël Gomès <rgomes@octobus.net>
parents:
49488
diff
changeset
|
302 ), |
49485
ffd4b1f1c9cb
rhg: add sparse support
Raphaël Gomès <rgomes@octobus.net>
parents:
49174
diff
changeset
|
303 SparseConfigError::HgError(e) => Self::from(e), |
ffd4b1f1c9cb
rhg: add sparse support
Raphaël Gomès <rgomes@octobus.net>
parents:
49174
diff
changeset
|
304 SparseConfigError::PatternError(e) => { |
ffd4b1f1c9cb
rhg: add sparse support
Raphaël Gomès <rgomes@octobus.net>
parents:
49174
diff
changeset
|
305 Self::unsupported(format!("{}", e)) |
ffd4b1f1c9cb
rhg: add sparse support
Raphaël Gomès <rgomes@octobus.net>
parents:
49174
diff
changeset
|
306 } |
ffd4b1f1c9cb
rhg: add sparse support
Raphaël Gomès <rgomes@octobus.net>
parents:
49174
diff
changeset
|
307 } |
ffd4b1f1c9cb
rhg: add sparse support
Raphaël Gomès <rgomes@octobus.net>
parents:
49174
diff
changeset
|
308 } |
ffd4b1f1c9cb
rhg: add sparse support
Raphaël Gomès <rgomes@octobus.net>
parents:
49174
diff
changeset
|
309 } |