Skip to content

Commit 2b7bc56

Browse files
committed
patch 8.0.0184: when an error is caught Vim still exits with non-zero result
Problem: When in Ex mode and an error is caught by try-catch, Vim still exits with a non-zero exit code. Solution: Don't set ex_exitval when inside a try-catch. (partly by Christian Brabandt)
1 parent 7173b47 commit 2b7bc56

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

src/message.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -578,8 +578,6 @@ emsg(char_u *s)
578578
return TRUE;
579579

580580
called_emsg = TRUE;
581-
if (emsg_silent == 0)
582-
ex_exitval = 1;
583581

584582
/*
585583
* If "emsg_severe" is TRUE: When an error exception is to be thrown,
@@ -642,6 +640,8 @@ emsg(char_u *s)
642640
return TRUE;
643641
}
644642

643+
ex_exitval = 1;
644+
645645
/* Reset msg_silent, an error causes messages to be switched back on. */
646646
msg_silent = 0;
647647
cmd_silent = FALSE;

src/testdir/test_system.vim

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,40 @@ function! Test_System()
4646

4747
call assert_fails('call system("wc -l", 99999)', 'E86:')
4848
endfunction
49+
50+
function! Test_system_exmode()
51+
let cmd=" -es -u NONE -c 'source Xscript' +q; echo $?"
52+
" Need to put this in a script, "catch" isn't found after an unknown
53+
" function.
54+
call writefile(['try', 'call doesnotexist()', 'catch', 'endtry'], 'Xscript')
55+
let a = system(v:progpath . cmd)
56+
call assert_equal('0', a[0])
57+
call assert_equal(0, v:shell_error)
58+
59+
" Error before try does set error flag.
60+
call writefile(['call nosuchfunction()', 'try', 'call doesnotexist()', 'catch', 'endtry'], 'Xscript')
61+
let a = system(v:progpath . cmd)
62+
call assert_notequal('0', a[0])
63+
64+
let cmd=" -es -u NONE -c 'source Xscript' +q"
65+
let a = system(v:progpath . cmd)
66+
call assert_notequal(0, v:shell_error)
67+
68+
let cmd=" -es -u NONE -c 'call doesnotexist()' +q; echo $?"
69+
let a = system(v:progpath. cmd)
70+
call assert_notequal(0, a[0])
71+
72+
let cmd=" -es -u NONE -c 'call doesnotexist()' +q"
73+
let a = system(v:progpath. cmd)
74+
call assert_notequal(0, v:shell_error)
75+
76+
let cmd=" -es -u NONE -c 'call doesnotexist()|let a=1' +q; echo $?"
77+
let a = system(v:progpath. cmd)
78+
call assert_notequal(0, a[0])
79+
80+
let cmd=" -es -u NONE -c 'call doesnotexist()|let a=1' +q"
81+
let a = system(v:progpath. cmd)
82+
call assert_notequal(0, v:shell_error)
83+
84+
call delete('Xscript')
85+
endfunc

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,8 @@ static char *(features[]) =
764764

765765
static int included_patches[] =
766766
{ /* Add new patch number below this line */
767+
/**/
768+
184,
767769
/**/
768770
183,
769771
/**/

0 commit comments

Comments
 (0)