From 68453843d459f5aaeffe7493497f6c8aba3c9191 Mon Sep 17 00:00:00 2001 From: Nahor Date: Tue, 31 Mar 2026 17:22:31 -0700 Subject: [PATCH] set: fix unreachable error messages - Remove unreachable error message in `handle_env_return()` While we could have put an empty block in `handle_env_return()` and removed the condition on `NotFound` in `erase()`, we prefered to use `unreachable!` in case `handle_env_return()` gets called in new scenarios in the future - Make reachable the error message when asking to show a slice Part of #12603 --- localization/po/de.po | 4 ---- localization/po/en.po | 4 ---- localization/po/es.po | 4 ---- localization/po/fr.po | 4 ---- localization/po/ja_JP.po | 4 ---- localization/po/pl.po | 4 ---- localization/po/pt_BR.po | 4 ---- localization/po/sv.po | 4 ---- localization/po/zh_CN.po | 4 ---- localization/po/zh_TW.po | 4 ---- src/builtins/set.rs | 16 ++++++++++------ tests/checks/set.fish | 17 +++++++++-------- 12 files changed, 19 insertions(+), 54 deletions(-) diff --git a/localization/po/de.po b/localization/po/de.po index 1d971fc2d..f73d57358 100644 --- a/localization/po/de.po +++ b/localization/po/de.po @@ -575,10 +575,6 @@ msgstr "" msgid "%s: The directory '%s' does not exist" msgstr "%s: Das Verzeichnis '%s' existiert nicht" -#, c-format -msgid "%s: The variable '%s' does not exist" -msgstr "" - #, c-format msgid "%s: There are no jobs" msgstr "%s: Es gibt keine Jobs" diff --git a/localization/po/en.po b/localization/po/en.po index 92f8873d8..6cbf9aa10 100644 --- a/localization/po/en.po +++ b/localization/po/en.po @@ -575,10 +575,6 @@ msgstr "" msgid "%s: The directory '%s' does not exist" msgstr "%s: The directory “%s” does not exist" -#, c-format -msgid "%s: The variable '%s' does not exist" -msgstr "" - #, c-format msgid "%s: There are no jobs" msgstr "%s: There are no jobs" diff --git a/localization/po/es.po b/localization/po/es.po index 1c99f1250..bfce044a6 100644 --- a/localization/po/es.po +++ b/localization/po/es.po @@ -575,10 +575,6 @@ msgstr "%s: La opción corta '%c' no es válida, debe ser alfanumérica o '#'" msgid "%s: The directory '%s' does not exist" msgstr "%s: El directorio '%s' no existe" -#, c-format -msgid "%s: The variable '%s' does not exist" -msgstr "%s: La variable '%s' no existe" - #, c-format msgid "%s: There are no jobs" msgstr "%s: No hay trabajos" diff --git a/localization/po/fr.po b/localization/po/fr.po index 93b5b627b..102006dda 100644 --- a/localization/po/fr.po +++ b/localization/po/fr.po @@ -704,10 +704,6 @@ msgstr "%s : Le sémaphore « %c » est invalide : il doit être alphanumér msgid "%s: The directory '%s' does not exist" msgstr "%s : Le dossier « %s » n’existe pas" -#, c-format -msgid "%s: The variable '%s' does not exist" -msgstr "" - #, c-format msgid "%s: There are no jobs" msgstr "%s : Aucune tâche" diff --git a/localization/po/ja_JP.po b/localization/po/ja_JP.po index d51d8a2f4..ccddd04a4 100644 --- a/localization/po/ja_JP.po +++ b/localization/po/ja_JP.po @@ -574,10 +574,6 @@ msgstr "%s: 短縮フラグ '%c' は無効です。英数字または '#' であ msgid "%s: The directory '%s' does not exist" msgstr "%s: ディレクトリ '%s' は存在しません" -#, c-format -msgid "%s: The variable '%s' does not exist" -msgstr "%s: 変数 '%s' は存在しません" - #, c-format msgid "%s: There are no jobs" msgstr "%s: ジョブはありません" diff --git a/localization/po/pl.po b/localization/po/pl.po index 2052b23c4..342e5e742 100644 --- a/localization/po/pl.po +++ b/localization/po/pl.po @@ -571,10 +571,6 @@ msgstr "" msgid "%s: The directory '%s' does not exist" msgstr "%s: Ścieżka '%s' nie istnieje" -#, c-format -msgid "%s: The variable '%s' does not exist" -msgstr "" - #, c-format msgid "%s: There are no jobs" msgstr "%s: Nie ma żadnych zadań" diff --git a/localization/po/pt_BR.po b/localization/po/pt_BR.po index b49dbf042..1f4cdeefd 100644 --- a/localization/po/pt_BR.po +++ b/localization/po/pt_BR.po @@ -576,10 +576,6 @@ msgstr "" msgid "%s: The directory '%s' does not exist" msgstr "%s: O diretório “%s” não existe" -#, c-format -msgid "%s: The variable '%s' does not exist" -msgstr "" - #, c-format msgid "%s: There are no jobs" msgstr "%s: Não há tarefas" diff --git a/localization/po/sv.po b/localization/po/sv.po index d61de8bb1..ac946f065 100644 --- a/localization/po/sv.po +++ b/localization/po/sv.po @@ -572,10 +572,6 @@ msgstr "" msgid "%s: The directory '%s' does not exist" msgstr "%s: Katalogen '%s' existerar inte" -#, c-format -msgid "%s: The variable '%s' does not exist" -msgstr "" - #, c-format msgid "%s: There are no jobs" msgstr "%s: Det finns inga jobb" diff --git a/localization/po/zh_CN.po b/localization/po/zh_CN.po index 2452e74b5..3baf7ce26 100644 --- a/localization/po/zh_CN.po +++ b/localization/po/zh_CN.po @@ -596,10 +596,6 @@ msgstr "%s: 短标识 '%c' 无效,必须是字母、数字或 '#'" msgid "%s: The directory '%s' does not exist" msgstr "%s: 目录 '%s' 不存在" -#, c-format -msgid "%s: The variable '%s' does not exist" -msgstr "%s: 变量 '%s' 不存在" - #, c-format msgid "%s: There are no jobs" msgstr "%s: 没有作业" diff --git a/localization/po/zh_TW.po b/localization/po/zh_TW.po index 17b29029e..2c89c4550 100644 --- a/localization/po/zh_TW.po +++ b/localization/po/zh_TW.po @@ -569,10 +569,6 @@ msgstr "%s:短旗標「%c」無效,必須是字母、數字、或「#」" msgid "%s: The directory '%s' does not exist" msgstr "%s:目錄「%s」不存在" -#, c-format -msgid "%s: The variable '%s' does not exist" -msgstr "%s:變數「%s」不存在" - #, c-format msgid "%s: There are no jobs" msgstr "%s:沒有作業" diff --git a/src/builtins/set.rs b/src/builtins/set.rs index d7bd8e39d..5a8910395 100644 --- a/src/builtins/set.rs +++ b/src/builtins/set.rs @@ -351,11 +351,8 @@ fn handle_env_return(retval: EnvStackSetResult, cmd: &wstr, key: &wstr, streams: )); } EnvStackSetResult::NotFound => { - streams.err.appendln(&wgettext_fmt!( - "%s: The variable '%s' does not exist", - cmd, - key - )); + // Only variable deletion can return a `NotFound` error, but that case is explicitly silenced + unreachable!("variable not found"); } } } @@ -729,13 +726,20 @@ fn show(cmd: &wstr, parser: &Parser, streams: &mut IoStreams, args: &[&wstr]) -> } } else { for arg in args.iter().copied() { + let bracket = arg.find(L!("[")); + let arg = if let Some(idx) = bracket { + &arg[..idx] + } else { + arg + }; + if !valid_var_name(arg) { streams.err.append(&varname_error(cmd, arg)); builtin_print_error_trailer(parser, streams.err, cmd); return Err(STATUS_INVALID_ARGS); } - if arg.contains('[') { + if bracket.is_some() { streams.err.appendln(&wgettext_fmt!( "%s: `set --show` does not allow slices with the var names", cmd diff --git a/tests/checks/set.fish b/tests/checks/set.fish index 018a2225c..cda623520 100644 --- a/tests/checks/set.fish +++ b/tests/checks/set.fish @@ -49,7 +49,6 @@ else end # CHECK: Test 4 pass - #Test that scope is preserved when setting a new value set t5 a @@ -79,7 +78,6 @@ for i in 1 end # CHECK: Test 6 pass - # Test if variables in for loop blocks do not go out of scope on new laps set res fail @@ -405,7 +403,6 @@ set -x DONT_ESCAPE_COLONS_PATH 1: 2: :3: env | grep '^DONT_ESCAPE_COLONS_PATH=' # CHECK: DONT_ESCAPE_COLONS_PATH=1::2:::3: - # Path universal variables set -U __fish_test_path_not a b c set -U __fish_test_PATH 1 2 3 @@ -485,7 +482,6 @@ set -g __fish_test_global_vs_universal global echo "global-vs-universal 2: $__fish_test_global_vs_universal" # CHECK: global-vs-universal 2: global - set __fish_test_global_vs_universal global2 echo "global-vs-universal 3: $__fish_test_global_vs_universal" # CHECK: global-vs-universal 3: global2 @@ -537,6 +533,13 @@ set --show 'argle bargle' #CHECKERR: ^ #CHECKERR: (Type 'help set' for related documentation) +set --show array[1] +# CHECKERR: set: `set --show` does not allow slices with the var names +# CHECKERR: {{.*}}set.fish (line {{\d+}}): +# CHECKERR: set --show array[1] +# CHECKERR: ^ +# CHECKERR: (Type 'help set' for related documentation) + # Verify behavior of `set --show` set semiempty '' set --show semiempty @@ -747,7 +750,6 @@ echo $foo echo $bar #CHECK: 1 3 - # Test that `set -q` does not return 0 if there are 256 missing variables set -lq a(seq 1 256) @@ -809,14 +811,14 @@ set -S stilllocal set -g globalvar global function test-function-scope - set -f funcvar "function" + set -f funcvar function echo $funcvar # CHECK: function set -S funcvar #CHECK: $funcvar: set in local scope, unexported, with 1 elements #CHECK: $funcvar[1]: |function| begin - set -l funcvar "block" + set -l funcvar block echo $funcvar # CHECK: block set -S funcvar @@ -1015,7 +1017,6 @@ set line[0] "" # CHECKERR: ^ # CHECKERR: (Type 'help set' for related documentation) - echo Still here # CHECK: Still here