]> granicus.if.org Git - vim/commitdiff
patch 8.2.3833: error from term_start() not caught by try/catch v8.2.3833
authorichizok <gclient.gaap@gmail.com>
Fri, 17 Dec 2021 09:44:33 +0000 (09:44 +0000)
committerBram Moolenaar <Bram@vim.org>
Fri, 17 Dec 2021 09:44:33 +0000 (09:44 +0000)
Problem:    Error from term_start() not caught by try/catch.
Solution:   save and restore did_emsg when applying autocommands. (Ozaki
            Kiichi, closes #9361)

src/autocmd.c
src/testdir/test_terminal3.vim
src/version.c

index 5ec911ab741d12e90094ddb0ba0883b50b267d72..305679cf329ea402097ad8f1bdd1fd7fb62927d9 100644 (file)
@@ -1891,6 +1891,7 @@ apply_autocmds_group(
     int                did_save_redobuff = FALSE;
     save_redo_T        save_redo;
     int                save_KeyTyped = KeyTyped;
+    int                save_did_emsg;
     ESTACK_CHECK_DECLARATION
 
     /*
@@ -2171,9 +2172,13 @@ apply_autocmds_group(
            // make sure cursor and topline are valid
            check_lnums(TRUE);
 
+       save_did_emsg = did_emsg;
+
        do_cmdline(NULL, getnextac, (void *)&patcmd,
                                     DOCMD_NOWAIT|DOCMD_VERBOSE|DOCMD_REPEAT);
 
+       did_emsg += save_did_emsg;
+
        if (nesting == 1)
            // restore cursor and topline, unless they were changed
            reset_lnums();
index 9f84615f2445137374e347ae919a8b730db957e5..a351799a7e02ee8b8168231e76f5bfc83d7d7b08 100644 (file)
@@ -901,5 +901,25 @@ func Test_terminal_getwinpos()
   only!
 endfunc
 
+func Test_terminal_term_start_error()
+  func s:term_start_error() abort
+    try
+      return term_start([[]])
+    catch
+      return v:exception
+    finally
+      "
+    endtry
+  endfunc
+  autocmd WinEnter * call type(0)
+
+  " Must not crash in s:term_start_error, nor the exception thrown.
+  let result = s:term_start_error()
+  call assert_match('^Vim(return):E730:', result)
+
+  autocmd! WinEnter
+  delfunc s:term_start_error
+endfunc
+
 
 " vim: shiftwidth=2 sts=2 expandtab
index e3fb7c2ffbe7530400007904710d996d436dc82f..b2f02eca55e8b690b85fe80f0843f8818791269d 100644 (file)
@@ -749,6 +749,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3833,
 /**/
     3832,
 /**/