Skip to content

Commit b8fd24e

Browse files
committed
ln: remove panic in result function
found using `clippy::panic_in_result_fn`
1 parent 0b04f5e commit b8fd24e

3 files changed

Lines changed: 9 additions & 1 deletion

File tree

src/uu/ln/locales/en-US.ftl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ ln-help-verbose = print name of each linked file
2626
ln-error-target-is-not-directory = target {$target} is not a directory
2727
ln-error-same-file = {$file1} and {$file2} are the same file
2828
ln-error-missing-destination = missing destination file operand after {$operand}
29+
ln-error-missing-operand = missing operand
2930
ln-error-extra-operand = extra operand {$operand}
3031
Try '{$program} --help' for more information.
3132
ln-error-could-not-update = Could not update {$target}: {$error}

src/uu/ln/locales/fr-FR.ftl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ ln-help-verbose = afficher le nom de chaque fichier lié
2727
ln-error-target-is-not-directory = la cible {$target} n'est pas un répertoire
2828
ln-error-same-file = {$file1} et {$file2} sont le même fichier
2929
ln-error-missing-destination = opérande de fichier de destination manquant après {$operand}
30+
ln-error-missing-operand = opérande manquant
3031
ln-error-extra-operand = opérande supplémentaire {$operand}
3132
Essayez « {$program} --help » pour plus d'informations.
3233
ln-error-could-not-update = Impossible de mettre à jour {$target} : {$error}

src/uu/ln/src/ln.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ pub enum LnError {
7070
#[error("{}", translate!("ln-error-missing-destination", "operand" => _0.quote()))]
7171
MissingDestination(PathBuf),
7272

73+
#[error("{}", translate!("ln-error-missing-operand"))]
74+
MissingOperand,
75+
7376
#[error("{}", translate!("ln-error-extra-operand", "operand" => _0.quote(), "program" => _1.clone()))]
7477
ExtraOperand(OsString, String),
7578

@@ -270,6 +273,10 @@ pub fn uu_app() -> Command {
270273
///
271274
/// This is made public to allow other apps to use `ln` as a library.
272275
pub fn exec(files: &[PathBuf], settings: &Settings) -> LnResult<()> {
276+
if files.is_empty() {
277+
return Err(LnError::MissingOperand);
278+
}
279+
273280
// Handle cases where we create links in a directory first.
274281
if let Some(ref target_path) = settings.target_dir {
275282
// 4th form: a directory is specified by -t.
@@ -298,7 +305,6 @@ pub fn exec(files: &[PathBuf], settings: &Settings) -> LnResult<()> {
298305
uucore::execution_phrase().to_string(),
299306
));
300307
}
301-
assert!(!files.is_empty());
302308

303309
link(&files[0], &files[1], settings)
304310
}

0 commit comments

Comments
 (0)