From b8fd24e023c8fb7f9121279a7c80655ee6799004 Mon Sep 17 00:00:00 2001 From: xtqqczze <45661989+xtqqczze@users.noreply.github.com> Date: Tue, 12 May 2026 13:11:49 +0100 Subject: [PATCH] ln: remove panic in result function found using `clippy::panic_in_result_fn` --- src/uu/ln/locales/en-US.ftl | 1 + src/uu/ln/locales/fr-FR.ftl | 1 + src/uu/ln/src/ln.rs | 8 +++++++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/uu/ln/locales/en-US.ftl b/src/uu/ln/locales/en-US.ftl index 337d5c2a0d9..a28f1212302 100644 --- a/src/uu/ln/locales/en-US.ftl +++ b/src/uu/ln/locales/en-US.ftl @@ -26,6 +26,7 @@ ln-help-verbose = print name of each linked file ln-error-target-is-not-directory = target {$target} is not a directory ln-error-same-file = {$file1} and {$file2} are the same file ln-error-missing-destination = missing destination file operand after {$operand} +ln-error-missing-operand = missing operand ln-error-extra-operand = extra operand {$operand} Try '{$program} --help' for more information. ln-error-could-not-update = Could not update {$target}: {$error} diff --git a/src/uu/ln/locales/fr-FR.ftl b/src/uu/ln/locales/fr-FR.ftl index d8ba0996722..56e72f3e55c 100644 --- a/src/uu/ln/locales/fr-FR.ftl +++ b/src/uu/ln/locales/fr-FR.ftl @@ -27,6 +27,7 @@ ln-help-verbose = afficher le nom de chaque fichier lié ln-error-target-is-not-directory = la cible {$target} n'est pas un répertoire ln-error-same-file = {$file1} et {$file2} sont le même fichier ln-error-missing-destination = opérande de fichier de destination manquant après {$operand} +ln-error-missing-operand = opérande manquant ln-error-extra-operand = opérande supplémentaire {$operand} Essayez « {$program} --help » pour plus d'informations. ln-error-could-not-update = Impossible de mettre à jour {$target} : {$error} diff --git a/src/uu/ln/src/ln.rs b/src/uu/ln/src/ln.rs index 96e708b2b1a..d227d4f538b 100644 --- a/src/uu/ln/src/ln.rs +++ b/src/uu/ln/src/ln.rs @@ -70,6 +70,9 @@ pub enum LnError { #[error("{}", translate!("ln-error-missing-destination", "operand" => _0.quote()))] MissingDestination(PathBuf), + #[error("{}", translate!("ln-error-missing-operand"))] + MissingOperand, + #[error("{}", translate!("ln-error-extra-operand", "operand" => _0.quote(), "program" => _1.clone()))] ExtraOperand(OsString, String), @@ -270,6 +273,10 @@ pub fn uu_app() -> Command { /// /// This is made public to allow other apps to use `ln` as a library. pub fn exec(files: &[PathBuf], settings: &Settings) -> LnResult<()> { + if files.is_empty() { + return Err(LnError::MissingOperand); + } + // Handle cases where we create links in a directory first. if let Some(ref target_path) = settings.target_dir { // 4th form: a directory is specified by -t. @@ -298,7 +305,6 @@ pub fn exec(files: &[PathBuf], settings: &Settings) -> LnResult<()> { uucore::execution_phrase().to_string(), )); } - assert!(!files.is_empty()); link(&files[0], &files[1], settings) }