Skip to content

Commit 7e8c1ba

Browse files
xtqqczzecakebaker
authored andcommitted
refactor: simplify UError construction
1 parent ba94c69 commit 7e8c1ba

5 files changed

Lines changed: 21 additions & 24 deletions

File tree

src/uu/base32/src/base_common.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ pub mod fast_decode {
741741
} else if ignore_garbage {
742742
continue;
743743
} else {
744-
return Err(USimpleError::new(1, "error: invalid input".to_owned()));
744+
return Err(USimpleError::new(1, "error: invalid input"));
745745
}
746746

747747
if supports_partial_decode {
@@ -790,7 +790,7 @@ pub mod fast_decode {
790790
write_to_output(&mut decoded_buffer, output)?;
791791

792792
if had_invalid_tail {
793-
return Err(USimpleError::new(1, "error: invalid input".to_owned()));
793+
return Err(USimpleError::new(1, "error: invalid input"));
794794
}
795795
}
796796

@@ -857,7 +857,7 @@ pub mod fast_decode {
857857
buffer.drain(..decode_in_chunks_of_size);
858858
}
859859
}
860-
return Err(USimpleError::new(1, "error: invalid input".to_owned()));
860+
return Err(USimpleError::new(1, "error: invalid input"));
861861
}
862862

863863
if supports_partial_decode {
@@ -909,7 +909,7 @@ pub mod fast_decode {
909909
write_to_output(&mut decoded_buffer, output)?;
910910

911911
if had_invalid_tail {
912-
return Err(USimpleError::new(1, "error: invalid input".to_owned()));
912+
return Err(USimpleError::new(1, "error: invalid input"));
913913
}
914914
}
915915

src/uu/stdbuf/src/stdbuf.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
223223

224224
let mut command_values = matches
225225
.get_many::<OsString>(options::COMMAND)
226-
.ok_or_else(|| UUsageError::new(125, "no command specified".to_string()))?;
226+
.ok_or_else(|| UUsageError::new(125, "no command specified"))?;
227227
let Some(first_command) = command_values.next() else {
228-
return Err(UUsageError::new(125, "no command specified".to_string()));
228+
return Err(UUsageError::new(125, "no command specified"));
229229
};
230230
let mut command = process::Command::new(first_command);
231231
let command_params: Vec<&OsString> = command_values.collect();

src/uu/unexpand/src/unexpand.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,10 +283,10 @@ fn open(path: &OsString) -> UResult<BufReader<Box<dyn Read + 'static>>> {
283283
let file_buf;
284284
let filename = Path::new(path);
285285
if filename.is_dir() {
286-
Err(Box::new(USimpleError {
287-
code: 1,
288-
message: translate!("unexpand-error-is-directory", "path" => filename.maybe_quote()),
289-
}))
286+
Err(USimpleError::new(
287+
1,
288+
translate!("unexpand-error-is-directory", "path" => filename.maybe_quote()),
289+
))
290290
} else if path == "-" {
291291
Ok(BufReader::new(Box::new(stdin()) as Box<dyn Read>))
292292
} else {

src/uucore/src/lib/features/encoding.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,11 @@ impl SupportsFastDecodeAndEncode for Base64SimdWrapper {
8888
let segment_len = blocks * 4;
8989

9090
if segment_len > remaining.len() {
91-
return Err(USimpleError::new(1, "error: invalid input".to_owned()));
91+
return Err(USimpleError::new(1, "error: invalid input"));
9292
}
9393

9494
if Self::decode_with_standard(&remaining[..segment_len], output).is_err() {
95-
return Err(USimpleError::new(1, "error: invalid input".to_owned()));
95+
return Err(USimpleError::new(1, "error: invalid input"));
9696
}
9797

9898
start += segment_len;
@@ -107,7 +107,7 @@ impl SupportsFastDecodeAndEncode for Base64SimdWrapper {
107107
};
108108

109109
if decoder(remaining, output).is_err() {
110-
return Err(USimpleError::new(1, "error: invalid input".to_owned()));
110+
return Err(USimpleError::new(1, "error: invalid input"));
111111
}
112112

113113
break;
@@ -117,7 +117,7 @@ impl SupportsFastDecodeAndEncode for Base64SimdWrapper {
117117
Ok(())
118118
} else {
119119
Self::decode_with_no_pad(input, output)
120-
.map_err(|_| USimpleError::new(1, "error: invalid input".to_owned()))
120+
.map_err(|_| USimpleError::new(1, "error: invalid input"))
121121
};
122122

123123
if let Err(err) = decode_result {
@@ -295,7 +295,7 @@ impl SupportsFastDecodeAndEncode for Base58Wrapper {
295295
let digit = alphabet
296296
.iter()
297297
.position(|&b| b == byte)
298-
.ok_or_else(|| USimpleError::new(1, "error: invalid input".to_owned()))?;
298+
.ok_or_else(|| USimpleError::new(1, "error: invalid input"))?;
299299

300300
// Multiply by 58 and add digit
301301
let mut carry = digit as u32;
@@ -426,13 +426,13 @@ impl SupportsFastDecodeAndEncode for Z85Wrapper {
426426

427427
fn decode_into_vec(&self, input: &[u8], output: &mut Vec<u8>) -> UResult<()> {
428428
if input.first() == Some(&b'#') {
429-
return Err(USimpleError::new(1, "error: invalid input".to_owned()));
429+
return Err(USimpleError::new(1, "error: invalid input"));
430430
}
431431

432432
let decode_result = match z85::decode(input) {
433433
Ok(ve) => ve,
434434
Err(_de) => {
435-
return Err(USimpleError::new(1, "error: invalid input".to_owned()));
435+
return Err(USimpleError::new(1, "error: invalid input"));
436436
}
437437
};
438438

@@ -451,7 +451,7 @@ impl SupportsFastDecodeAndEncode for Z85Wrapper {
451451
if !input.len().is_multiple_of(4) {
452452
return Err(USimpleError::new(
453453
1,
454-
"error: invalid input (length must be multiple of 4 characters)".to_owned(),
454+
"error: invalid input (length must be multiple of 4 characters)",
455455
));
456456
}
457457

@@ -477,7 +477,7 @@ impl SupportsFastDecodeAndEncode for EncodingWrapper {
477477
let decode_len_result = match self.encoding.decode_len(input.len()) {
478478
Ok(us) => us,
479479
Err(_de) => {
480-
return Err(USimpleError::new(1, "error: invalid input".to_owned()));
480+
return Err(USimpleError::new(1, "error: invalid input"));
481481
}
482482
};
483483

@@ -493,7 +493,7 @@ impl SupportsFastDecodeAndEncode for EncodingWrapper {
493493
output.truncate(output_len + us);
494494
}
495495
Err(_de) => {
496-
return Err(USimpleError::new(1, "error: invalid input".to_owned()));
496+
return Err(USimpleError::new(1, "error: invalid input"));
497497
}
498498
}
499499

src/uucore/src/lib/features/perms.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -830,10 +830,7 @@ pub fn configure_symlink_and_recursion(
830830
if recursive {
831831
if traverse_symlinks == TraverseSymlinks::None {
832832
if dereference == Some(true) {
833-
return Err(USimpleError::new(
834-
1,
835-
"-R --dereference requires -H or -L".to_string(),
836-
));
833+
return Err(USimpleError::new(1, "-R --dereference requires -H or -L"));
837834
}
838835
dereference = Some(false);
839836
}

0 commit comments

Comments
 (0)