##// END OF EJS Templates
rhg: use `format_bytes!` for error messages...
Raphaël Gomès -
r46598:fada3387 default
parent child Browse files
Show More
@@ -210,6 +210,26 b' dependencies = ['
210 ]
210 ]
211
211
212 [[package]]
212 [[package]]
213 name = "format-bytes"
214 version = "0.1.3"
215 source = "registry+https://github.com/rust-lang/crates.io-index"
216 dependencies = [
217 "format-bytes-macros 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
218 "proc-macro-hack 0.5.19 (registry+https://github.com/rust-lang/crates.io-index)",
219 ]
220
221 [[package]]
222 name = "format-bytes-macros"
223 version = "0.1.2"
224 source = "registry+https://github.com/rust-lang/crates.io-index"
225 dependencies = [
226 "proc-macro-hack 0.5.19 (registry+https://github.com/rust-lang/crates.io-index)",
227 "proc-macro2 1.0.21 (registry+https://github.com/rust-lang/crates.io-index)",
228 "quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
229 "syn 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)",
230 ]
231
232 [[package]]
213 name = "fuchsia-cprng"
233 name = "fuchsia-cprng"
214 version = "0.1.1"
234 version = "0.1.1"
215 source = "registry+https://github.com/rust-lang/crates.io-index"
235 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -454,6 +474,11 b' dependencies = ['
454 ]
474 ]
455
475
456 [[package]]
476 [[package]]
477 name = "proc-macro-hack"
478 version = "0.5.19"
479 source = "registry+https://github.com/rust-lang/crates.io-index"
480
481 [[package]]
457 name = "proc-macro2"
482 name = "proc-macro2"
458 version = "1.0.21"
483 version = "1.0.21"
459 source = "registry+https://github.com/rust-lang/crates.io-index"
484 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -653,6 +678,7 b' version = "0.1.0"'
653 dependencies = [
678 dependencies = [
654 "clap 2.33.3 (registry+https://github.com/rust-lang/crates.io-index)",
679 "clap 2.33.3 (registry+https://github.com/rust-lang/crates.io-index)",
655 "env_logger 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
680 "env_logger 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
681 "format-bytes 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
656 "hg-core 0.1.0",
682 "hg-core 0.1.0",
657 "log 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)",
683 "log 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)",
658 "micro-timer 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
684 "micro-timer 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -887,6 +913,8 b' dependencies = ['
887 "checksum either 1.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457"
913 "checksum either 1.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457"
888 "checksum env_logger 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36"
914 "checksum env_logger 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36"
889 "checksum flate2 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)" = "766d0e77a2c1502169d4a93ff3b8c15a71fd946cd0126309752104e5f3c46d94"
915 "checksum flate2 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)" = "766d0e77a2c1502169d4a93ff3b8c15a71fd946cd0126309752104e5f3c46d94"
916 "checksum format-bytes 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1a7374eb574cd29ae45878554298091c554c3286a17b3afa440a3e2710ae0790"
917 "checksum format-bytes-macros 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4edcc04201cea17a0e6b937adebd46b93fba09924c7e6ed8c515a35ce8432cbc"
890 "checksum fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba"
918 "checksum fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba"
891 "checksum gcc 0.3.55 (registry+https://github.com/rust-lang/crates.io-index)" = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2"
919 "checksum gcc 0.3.55 (registry+https://github.com/rust-lang/crates.io-index)" = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2"
892 "checksum getrandom 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)" = "fc587bc0ec293155d5bfa6b9891ec18a1e330c234f896ea47fbada4cadbe47e6"
920 "checksum getrandom 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)" = "fc587bc0ec293155d5bfa6b9891ec18a1e330c234f896ea47fbada4cadbe47e6"
@@ -914,6 +942,7 b' dependencies = ['
914 "checksum pkg-config 0.3.18 (registry+https://github.com/rust-lang/crates.io-index)" = "d36492546b6af1463394d46f0c834346f31548646f6ba10849802c9c9a27ac33"
942 "checksum pkg-config 0.3.18 (registry+https://github.com/rust-lang/crates.io-index)" = "d36492546b6af1463394d46f0c834346f31548646f6ba10849802c9c9a27ac33"
915 "checksum ppv-lite86 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)" = "c36fa947111f5c62a733b652544dd0016a43ce89619538a8ef92724a6f501a20"
943 "checksum ppv-lite86 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)" = "c36fa947111f5c62a733b652544dd0016a43ce89619538a8ef92724a6f501a20"
916 "checksum pretty_assertions 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3f81e1644e1b54f5a68959a29aa86cde704219254669da328ecfdf6a1f09d427"
944 "checksum pretty_assertions 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3f81e1644e1b54f5a68959a29aa86cde704219254669da328ecfdf6a1f09d427"
945 "checksum proc-macro-hack 0.5.19 (registry+https://github.com/rust-lang/crates.io-index)" = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5"
917 "checksum proc-macro2 1.0.21 (registry+https://github.com/rust-lang/crates.io-index)" = "36e28516df94f3dd551a587da5357459d9b36d945a7c37c3557928c1c2ff2a2c"
946 "checksum proc-macro2 1.0.21 (registry+https://github.com/rust-lang/crates.io-index)" = "36e28516df94f3dd551a587da5357459d9b36d945a7c37c3557928c1c2ff2a2c"
918 "checksum python27-sys 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "67cb041de8615111bf224dd75667af5f25c6e032118251426fed7f1b70ce4c8c"
947 "checksum python27-sys 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "67cb041de8615111bf224dd75667af5f25c6e032118251426fed7f1b70ce4c8c"
919 "checksum python3-sys 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "90af11779515a1e530af60782d273b59ac79d33b0e253c071a728563957c76d4"
948 "checksum python3-sys 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "90af11779515a1e530af60782d273b59ac79d33b0e253c071a728563957c76d4"
@@ -1,7 +1,10 b''
1 [package]
1 [package]
2 name = "rhg"
2 name = "rhg"
3 version = "0.1.0"
3 version = "0.1.0"
4 authors = ["Antoine Cezar <antoine.cezar@octobus.net>"]
4 authors = [
5 "Antoine Cezar <antoine.cezar@octobus.net>",
6 "Raphaël Gomès <raphael.gomes@octobus.net>",
7 ]
5 edition = "2018"
8 edition = "2018"
6
9
7 [dependencies]
10 [dependencies]
@@ -10,3 +13,4 b' clap = "2.33.1"'
10 log = "0.4.11"
13 log = "0.4.11"
11 micro-timer = "0.3.1"
14 micro-timer = "0.3.1"
12 env_logger = "0.7.1"
15 env_logger = "0.7.1"
16 format-bytes = "0.1.3"
@@ -1,6 +1,7 b''
1 use crate::commands::Command;
1 use crate::commands::Command;
2 use crate::error::CommandError;
2 use crate::error::CommandError;
3 use crate::ui::Ui;
3 use crate::ui::Ui;
4 use format_bytes::format_bytes;
4 use hg::operations::FindRoot;
5 use hg::operations::FindRoot;
5 use hg::utils::files::get_bytes_from_path;
6 use hg::utils::files::get_bytes_from_path;
6
7
@@ -24,8 +25,7 b' impl Command for RootCommand {'
24
25
25 let bytes = get_bytes_from_path(path_buf);
26 let bytes = get_bytes_from_path(path_buf);
26
27
27 // TODO use formating macro
28 ui.write_stdout(&format_bytes!(b"{}\n", bytes.as_slice()))?;
28 ui.write_stdout(&[bytes.as_slice(), b"\n"].concat())?;
29
29
30 Ok(())
30 Ok(())
31 }
31 }
@@ -1,5 +1,6 b''
1 use crate::exitcode;
1 use crate::exitcode;
2 use crate::ui::UiError;
2 use crate::ui::UiError;
3 use format_bytes::format_bytes;
3 use hg::operations::{FindRootError, FindRootErrorKind};
4 use hg::operations::{FindRootError, FindRootErrorKind};
4 use hg::requirements::RequirementsError;
5 use hg::requirements::RequirementsError;
5 use hg::utils::files::get_bytes_from_path;
6 use hg::utils::files::get_bytes_from_path;
@@ -44,27 +45,17 b' impl CommandErrorKind {'
44 /// Return the message corresponding to the error kind if any
45 /// Return the message corresponding to the error kind if any
45 pub fn get_error_message_bytes(&self) -> Option<Vec<u8>> {
46 pub fn get_error_message_bytes(&self) -> Option<Vec<u8>> {
46 match self {
47 match self {
47 // TODO use formating macro
48 CommandErrorKind::RootNotFound(path) => {
48 CommandErrorKind::RootNotFound(path) => {
49 let bytes = get_bytes_from_path(path);
49 let bytes = get_bytes_from_path(path);
50 Some(
50 Some(format_bytes!(
51 [
51 b"abort: no repository found in '{}' (.hg not found)!\n",
52 b"abort: no repository found in '",
52 bytes.as_slice()
53 bytes.as_slice(),
53 ))
54 b"' (.hg not found)!\n",
55 ]
56 .concat(),
57 )
58 }
54 }
59 // TODO use formating macro
55 CommandErrorKind::CurrentDirNotFound(e) => Some(format_bytes!(
60 CommandErrorKind::CurrentDirNotFound(e) => Some(
56 b"abort: error getting current working directory: {}\n",
61 [
57 e.to_string().as_bytes(),
62 b"abort: error getting current working directory: ",
58 )),
63 e.to_string().as_bytes(),
64 b"\n",
65 ]
66 .concat(),
67 ),
68 CommandErrorKind::RequirementsError(
59 CommandErrorKind::RequirementsError(
69 RequirementsError::Corrupted,
60 RequirementsError::Corrupted,
70 ) => Some(
61 ) => Some(
@@ -1,3 +1,4 b''
1 use format_bytes::format_bytes;
1 use std::borrow::Cow;
2 use std::borrow::Cow;
2 use std::io;
3 use std::io;
3 use std::io::{ErrorKind, Write};
4 use std::io::{ErrorKind, Write};
@@ -87,7 +88,10 b' fn handle_stdout_error(error: io::Error)'
87 let mut stderr = io::stderr();
88 let mut stderr = io::stderr();
88
89
89 stderr
90 stderr
90 .write_all(&[b"abort: ", error.to_string().as_bytes(), b"\n"].concat())
91 .write_all(&format_bytes!(
92 b"abort: {}\n",
93 error.to_string().as_bytes()
94 ))
91 .map_err(UiError::StderrError)?;
95 .map_err(UiError::StderrError)?;
92
96
93 stderr.flush().map_err(UiError::StderrError)?;
97 stderr.flush().map_err(UiError::StderrError)?;
General Comments 0
You need to be logged in to leave comments. Login now