Skip to content

Commit e697667

Browse files
jayhemnani9910sylvestre
authored andcommitted
pmap: return the parse error from parse_address
1 parent 5a003b0 commit e697667

1 file changed

Lines changed: 6 additions & 11 deletions

File tree

‎src/uu/pmap/src/pmap.rs‎

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
9999
if let Some(range) = matches.get_one::<String>(options::RANGE) {
100100
match range.matches(',').count() {
101101
0 => {
102-
let address = parse_address(range).map_err(|_| {
103-
USimpleError::new(1, format!("failed to parse argument: '{range}'"))
104-
})?;
102+
let address = parse_address(range, range)?;
105103
pmap_config.range_low = address;
106104
pmap_config.range_high = address;
107105
}
@@ -112,16 +110,12 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
112110
pmap_config.range_low = if low.is_empty() {
113111
0
114112
} else {
115-
parse_address(low).map_err(|_| {
116-
USimpleError::new(1, format!("failed to parse argument: '{range}'"))
117-
})?
113+
parse_address(low, range)?
118114
};
119115
pmap_config.range_high = if high.is_empty() {
120116
u64::MAX
121117
} else {
122-
parse_address(high).map_err(|_| {
123-
USimpleError::new(1, format!("failed to parse argument: '{range}'"))
124-
})?
118+
parse_address(high, range)?
125119
};
126120
}
127121
_ => {
@@ -434,13 +428,14 @@ fn output_device_format(pid: &str, pmap_config: &PmapConfig) -> Result<(), Error
434428
}
435429

436430
/// Parse an address for --range: hexadecimal, with or without a 0x prefix,
437-
/// as procps-ng takes it.
438-
fn parse_address(address: &str) -> Result<u64, std::num::ParseIntError> {
431+
/// as procps-ng takes it. `range` is the whole argument, for the error.
432+
fn parse_address(address: &str, range: &str) -> UResult<u64> {
439433
let digits = address
440434
.strip_prefix("0x")
441435
.or_else(|| address.strip_prefix("0X"))
442436
.unwrap_or(address);
443437
u64::from_str_radix(digits, 16)
438+
.map_err(|_| USimpleError::new(1, format!("failed to parse argument: '{range}'")))
444439
}
445440

446441
pub fn uu_app() -> Command {

0 commit comments

Comments
 (0)