]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.0.1576: users may not know what to do with an internal error v9.0.1576
authorBram Moolenaar <Bram@vim.org>
Wed, 24 May 2023 20:02:24 +0000 (21:02 +0100)
committerBram Moolenaar <Bram@vim.org>
Wed, 24 May 2023 20:02:24 +0000 (21:02 +0100)
Problem:    Users may not know what to do with an internal error.
Solution:   Add a translated message with instructions.

15 files changed:
runtime/doc/message.txt
src/channel.c
src/errors.h
src/evalvars.c
src/ex_docmd.c
src/gui.c
src/message.c
src/regexp_nfa.c
src/testdir/test_expr.vim
src/testdir/test_functions.vim
src/testdir/test_listdict.vim
src/testdir/test_vimscript.vim
src/userfunc.c
src/version.c
src/window.c

index 2e23ac4f95d971f19eb2293b1d3102dc0413d09b..c774ff9b81dc9e6e4ee9b56d762498ee96b3fa32 100644 (file)
@@ -78,7 +78,7 @@ See `:messages` above.
 LIST OF MESSAGES
                        *E222* *E228* *E232* *E293* *E298* *E304* *E317*
                        *E318* *E356* *E438* *E439* *E440* *E316* *E320* *E322*
-                       *E323* *E341* *E473* *E570* *E685* *E292*
+                       *E323* *E341* *E473* *E570* *E292*
   Add to read buffer ~
   makemap: Illegal mode ~
   Cannot create BalloonEval with both message and callback ~
@@ -99,9 +99,9 @@ LIST OF MESSAGES
   Internal error in regexp ~
   fatal error in cs_manage_matches ~
   Invalid count for del_bytes(): {N} ~
-
+                                               *E340* *E685* *internal-error*
 This is an internal error.  If you can reproduce it, please send in a bug
-report. |bugs|
+report, see |bugs|.
 
 
   ATTENTION ~
index 97eb5db99c0bb3d6f596edc6a4bd9d02ab8d7c95..5d45ac6d1436c828a93ecfc36d4daaa51c1b8a84 100644 (file)
@@ -1757,7 +1757,7 @@ invoke_callback(channel_T *channel, callback_T *callback, typval_T *argv)
     typval_T   rettv;
 
     if (safe_to_invoke_callback == 0)
-       iemsg("INTERNAL: Invoking callback when it is not safe");
+       iemsg("Invoking callback when it is not safe");
 
     argv[0].v_type = VAR_CHANNEL;
     argv[0].vval.v_channel = channel;
@@ -2400,7 +2400,7 @@ channel_remove_block_id(chanpart_T *chanpart, int id)
            }
            return;
        }
-    siemsg("INTERNAL: channel_remove_block_id: cannot find id %d", id);
+    siemsg("channel_remove_block_id(): cannot find id %d", id);
 }
 
 /*
index 88dad4b75ec196dd493fbc43de4471f04cf47900..ddaa909ec8505fbcda05ea2152e2a0997a53b09c 100644 (file)
@@ -840,7 +840,8 @@ EXTERN char e_sorry_no_file_browser_in_console_mode[]
 #endif
 EXTERN char e_pattern_too_long[]
        INIT(= N_("E339: Pattern too long"));
-// E340 unused
+EXTERN char e_internal_error_please_report_a_bug[]
+       INIT(= N_("E340: Internal error; if you can reproduce please report a bug"));
 EXTERN char e_internal_error_lalloc_zero[]
        INIT(= N_("E341: Internal error: lalloc(0, )"));
 EXTERN char e_out_of_memory_allocating_nr_bytes[]
index b0df0a58b35947300d16c3c7e1390dcb216546a3..bebee2a5bcf802f70d6c1ae7d1927c9506126344 100644 (file)
@@ -206,7 +206,7 @@ evalvars_init(void)
        p = &vimvars[i];
        if (STRLEN(p->vv_name) > DICTITEM16_KEY_LEN)
        {
-           iemsg("INTERNAL: name too long, increase size of dictitem16_T");
+           iemsg("Name too long, increase size of dictitem16_T");
            getout(1);
        }
        STRCPY(p->vv_di.di_key, p->vv_name);
index 69af1ca1d074bf0db54b49a1e32f09c6989d8677..7cca73f12e542062e9b9702a71a8ec028d271225 100644 (file)
@@ -4716,7 +4716,7 @@ address_default_all(exarg_T *eap)
        case ADDR_NONE:
        case ADDR_UNSIGNED:
        case ADDR_QUICKFIX:
-           iemsg(_("INTERNAL: Cannot use EX_DFLALL with ADDR_NONE, ADDR_UNSIGNED or ADDR_QUICKFIX"));
+           iemsg("Cannot use EX_DFLALL with ADDR_NONE, ADDR_UNSIGNED or ADDR_QUICKFIX");
            break;
     }
 }
index e9f951da796b58c944c8e2690a895c157b39a901..1f546b2a75b57d53e5ec8420b896753fa33d57a8 100644 (file)
--- a/src/gui.c
+++ b/src/gui.c
@@ -142,7 +142,7 @@ gui_start(char_u *arg UNUSED)
        settmode(TMODE_RAW);            // restart RAW mode
        set_title_defaults();           // set 'title' and 'icon' again
 #if defined(GUI_MAY_SPAWN) && defined(EXPERIMENTAL_GUI_CMD)
-       if (msg)
+       if (msg != NULL)
            emsg(msg);
 #endif
     }
@@ -2786,14 +2786,8 @@ gui_redraw_block(
                if (col1 > 0)
                    --col1;
                else
-               {
                    // FIXME: how can the first character ever be zero?
-                   // Make this IEMSGN when it no longer breaks Travis CI.
-                   vim_snprintf((char *)IObuff, IOSIZE,
-                           "INTERNAL ERROR: NUL in ScreenLines in row %ld",
-                           (long)gui.row);
-                   msg((char *)IObuff);
-               }
+                   siemsg("NUL in ScreenLines in row %ld", (long)gui.row);
            }
 #ifdef FEAT_GUI_GTK
            if (col2 + 1 < Columns && ScreenLines[off + col2 + 1] == 0)
@@ -4400,9 +4394,9 @@ gui_do_scrollbar(
 }
 
 /*
- * Scroll a window according to the values set in the globals current_scrollbar
- * and scrollbar_value.  Return TRUE if the cursor in the current window moved
- * or FALSE otherwise.
+ * Scroll a window according to the values set in the globals
+ * "current_scrollbar" and "scrollbar_value".
+ * Return TRUE if the cursor in the current window moved or FALSE otherwise.
  */
     int
 gui_do_scroll(void)
index 18f3013805c15711c9f75f405dd93afc14383e40..985161d2e818c3590eed6337c0e42684f7b80862 100644 (file)
@@ -592,12 +592,12 @@ ignore_error_for_testing(char_u *error)
 }
 
     static int
-ignore_error(char_u *msg)
+ignore_error(const char *msg)
 {
     int i;
 
     for (i = 0; i < ignore_error_list.ga_len; ++i)
-       if (strstr((char *)msg,
+       if (strstr(msg,
                  (char *)((char_u **)(ignore_error_list.ga_data))[i]) != NULL)
            return TRUE;
     return FALSE;
@@ -629,7 +629,7 @@ do_perror(char *msg)
  * Note: caller must check 'emsg_not_now()' before calling this.
  */
     static int
-emsg_core(char_u *s)
+emsg_core(const char *s)
 {
     int                attr;
     char_u     *p;
@@ -665,7 +665,7 @@ emsg_core(char_u *s)
         * when the message should be ignored completely (used for the
         * interrupt message).
         */
-       if (cause_errthrow(s, severe, &ignore) == TRUE)
+       if (cause_errthrow((char_u *)s, severe, &ignore) == TRUE)
        {
            if (!ignore)
                ++did_emsg;
@@ -674,7 +674,7 @@ emsg_core(char_u *s)
 
        if (in_assert_fails && emsg_assert_fails_msg == NULL)
        {
-           emsg_assert_fails_msg = vim_strsave(s);
+           emsg_assert_fails_msg = vim_strsave((char_u *)s);
            emsg_assert_fails_lnum = SOURCING_LNUM;
            vim_free(emsg_assert_fails_context);
            emsg_assert_fails_context = vim_strsave(
@@ -682,7 +682,7 @@ emsg_core(char_u *s)
        }
 
        // set "v:errmsg", also when using ":silent! cmd"
-       set_vim_var_string(VV_ERRMSG, s, -1);
+       set_vim_var_string(VV_ERRMSG, (char_u *)s, -1);
 #endif
 
        /*
@@ -711,7 +711,7 @@ emsg_core(char_u *s)
                    redir_write(p, -1);
                    vim_free(p);
                }
-               redir_write(s, -1);
+               redir_write((char_u *)s, -1);
            }
 #ifdef FEAT_EVAL
            // Only increment did_emsg_def when :silent! wasn't used inside the
@@ -720,7 +720,7 @@ emsg_core(char_u *s)
                ++did_emsg_def;
 #endif
 #ifdef FEAT_EVAL
-           ch_log(NULL, "ERROR silent: %s", (char *)s);
+           ch_log(NULL, "ERROR silent: %s", s);
 #endif
            return TRUE;
        }
@@ -778,45 +778,44 @@ emsg_core(char_u *s)
 }
 
 /*
- * Print an error message.
+ * Print error message "s".  Should already be translated.
+ * Return TRUE if wait_return() not called.
  */
     int
 emsg(char *s)
 {
     // Skip this if not giving error messages at the moment.
-    if (!emsg_not_now())
-       return emsg_core((char_u *)s);
-    return TRUE;               // no error messages at the moment
+    if (emsg_not_now())
+       return TRUE;
+
+    return emsg_core(s);
 }
 
 #ifndef PROTO  // manual proto with __attribute__
 /*
- * Print an error message with format string and variable arguments.
- * Note: caller must not pass 'IObuff' as 1st argument.
+ * Print error message "s" with format string and variable arguments.
+ * "s" should already be translated.
+ * Note: caller must not use "IObuff" for "s"!
+ * Return TRUE if wait_return() not called.
  */
     int
 semsg(const char *s, ...)
 {
     // Skip this if not giving error messages at the moment.
-    if (!emsg_not_now())
-    {
-       if (IObuff == NULL)
-       {
-           // Very early in initialisation and already something wrong, just
-           // give the raw message so the user at least gets a hint.
-           return emsg_core((char_u *)s);
-       }
-       else
-       {
-           va_list ap;
+    if (emsg_not_now())
+       return TRUE;
 
-           va_start(ap, s);
-           vim_vsnprintf((char *)IObuff, IOSIZE, s, ap);
-           va_end(ap);
-           return emsg_core(IObuff);
-       }
-    }
-    return TRUE;               // no error messages at the moment
+    if (IObuff == NULL)
+       // Very early in initialisation and already something wrong, just
+       // give the raw message so the user at least gets a hint.
+       return emsg_core(s);
+
+    va_list ap;
+
+    va_start(ap, s);
+    vim_vsnprintf((char *)IObuff, IOSIZE, s, ap);
+    va_end(ap);
+    return emsg_core((char *)IObuff);
 }
 #endif
 
@@ -831,7 +830,11 @@ iemsg(char *s)
     if (emsg_not_now())
        return;
 
-    emsg_core((char_u *)s);
+    // Give a generic error which is translated.  The error itself may not be
+    // translated, it almost never shows.
+    emsg_core(_(e_internal_error_please_report_a_bug));
+
+    emsg_core(s);
 #if defined(ABORT_ON_INTERNAL_ERROR) && defined(FEAT_EVAL)
     set_vim_var_string(VV_ERRMSG, (char_u *)s, -1);
     msg_putchar('\n');  // avoid overwriting the error message
@@ -853,11 +856,15 @@ siemsg(const char *s, ...)
     if (emsg_not_now())
        return;
 
+    // Give a generic error which is translated.  The error itself may not be
+    // translated, it almost never shows.
+    emsg_core(_(e_internal_error_please_report_a_bug));
+
     if (IObuff == NULL)
     {
        // Very early in initialisation and already something wrong, just
        // give the raw message so the user at least gets a hint.
-       emsg_core((char_u *)s);
+       emsg_core(s);
     }
     else
     {
@@ -866,7 +873,7 @@ siemsg(const char *s, ...)
        va_start(ap, s);
        vim_vsnprintf((char *)IObuff, IOSIZE, s, ap);
        va_end(ap);
-       emsg_core(IObuff);
+       emsg_core((char *)IObuff);
     }
 # ifdef ABORT_ON_INTERNAL_ERROR
     msg_putchar('\n');  // avoid overwriting the error message
@@ -882,6 +889,10 @@ siemsg(const char *s, ...)
     void
 internal_error(char *where)
 {
+    // Give a generic error which is translated.  The error itself may not be
+    // translated, it almost never shows.
+    emsg_core(_(e_internal_error_please_report_a_bug));
+
     siemsg(_(e_internal_error_str), where);
 }
 
@@ -893,7 +904,11 @@ internal_error(char *where)
     void
 internal_error_no_abort(char *where)
 {
-     semsg(_(e_internal_error_str), where);
+    // Give a generic error which is translated.  The error itself may not be
+    // translated, it almost never shows.
+    emsg_core(_(e_internal_error_please_report_a_bug));
+
+    semsg(_(e_internal_error_str), where);
 }
 #endif
 
index b7bfc86c082ce8fb57715f835327a5b2131c46b5..72e5e255a9d91653b549951c9b02c9e5d7a933f9 100644 (file)
@@ -1401,7 +1401,7 @@ nfa_regatom(void)
                    rc_did_emsg = TRUE;
                    return FAIL;
                }
-               siemsg("INTERNAL: Unknown character class char: %d", c);
+               siemsg("Unknown character class char: %d", c);
                return FAIL;
            }
 
@@ -6905,7 +6905,7 @@ nfa_regmatch(
 
 #ifdef DEBUG
                if (c < 0)
-                   siemsg("INTERNAL: Negative state char: %ld", (long)c);
+                   siemsg("Negative state char: %ld", (long)c);
 #endif
                result = (c == curc);
 
@@ -7196,9 +7196,9 @@ nfa_regtry(
     if (f != NULL)
     {
        fprintf(f, "\n\n\t=======================================================\n");
-#ifdef DEBUG
+# ifdef DEBUG
        fprintf(f, "\tRegexp is \"%s\"\n", nfa_regengine.expr);
-#endif
+# endif
        fprintf(f, "\tInput text is \"%s\" \n", rex.input);
        fprintf(f, "\t=======================================================\n\n");
        nfa_print_state(f, start);
index 68cbeb59d0306ee9bb2b607425a75a31cae66e95..f7f6e653212549ae9d265fe744814db6c497de62 100644 (file)
@@ -25,7 +25,7 @@ func Test_equal()
   call assert_fails('echo base.method > instance.method')
   call assert_equal(0, test_null_function() == function('min'))
   call assert_equal(1, test_null_function() == test_null_function())
-  call assert_fails('eval 10 == test_unknown()', 'E685:')
+  call assert_fails('eval 10 == test_unknown()', ['E340:', 'E685:'])
 endfunc
 
 func Test_version()
index 8664724b5c6e2ba39275213043ceba713ae7fcf7..17a87d85e04a1761a7e0e5f8c3740446a0dffbb9 100644 (file)
@@ -82,15 +82,15 @@ func Test_empty()
   call assert_equal(0, empty(function('Test_empty')))
   call assert_equal(0, empty(function('Test_empty', [0])))
 
-  call assert_fails("call empty(test_void())", 'E685:')
-  call assert_fails("call empty(test_unknown())", 'E685:')
+  call assert_fails("call empty(test_void())", ['E340:', 'E685:'])
+  call assert_fails("call empty(test_unknown())", ['E340:', 'E685:'])
 endfunc
 
 func Test_test_void()
   call assert_fails('echo 1 == test_void()', 'E1031:')
   call assert_fails('echo 1.0 == test_void()', 'E1031:')
-  call assert_fails('let x = json_encode(test_void())', 'E685:')
-  call assert_fails('let x = copy(test_void())', 'E685:')
+  call assert_fails('let x = json_encode(test_void())', ['E340:', 'E685:'])
+  call assert_fails('let x = copy(test_void())', ['E340:', 'E685:'])
   call assert_fails('let x = copy([test_void()])', 'E1031:')
 endfunc
 
index 877bb80739a2eaeb841af192384e88d91b6fdabc..ac1f29b8fde9dcde411230dd2401a8574411cf27 100644 (file)
@@ -1384,7 +1384,7 @@ func Test_listdict_index()
   call v9.CheckLegacyAndVim9Failure(['VAR l = [1, 2, 3]', 'LET l[1.1] = 4'], ['E805:', 'E1012:', 'E805:'])
   call v9.CheckLegacyAndVim9Failure(['VAR l = [1, 2, 3]', 'LET l[: i] = [4, 5]'], ['E121:', 'E1001:', 'E121:'])
   call v9.CheckLegacyAndVim9Failure(['VAR l = [1, 2, 3]', 'LET l[: 3.2] = [4, 5]'], ['E805:', 'E1012:', 'E805:'])
-  call v9.CheckLegacyAndVim9Failure(['VAR t = test_unknown()', 'echo t[0]'], ['E685:', 'E909:', 'E685:'])
+  call v9.CheckLegacyAndVim9Failure(['VAR t = test_unknown()', 'echo t[0]'], ['E340:', 'E909:', 'E340:', 'E685:'])
 endfunc
 
 " Test for a null list
index 295a03b027663684678d68175ea141611f77ede6..2af0800bde603ff13b48603035a55a6650a57e37 100644 (file)
@@ -6524,8 +6524,8 @@ func Test_type()
     endif
     call assert_equal(v:t_blob, type(test_null_blob()))
 
-    call assert_fails("call type(test_void())", 'E685:')
-    call assert_fails("call type(test_unknown())", 'E685:')
+    call assert_fails("call type(test_void())", ['E340:', 'E685:'])
+    call assert_fails("call type(test_unknown())", ['E340:', 'E685:'])
 
     call assert_equal(0, 0 + v:false)
     call assert_equal(1, 0 + v:true)
index 5b2c876e3b53de42214a2bb99ddabe8b67204ad0..c30c3524bd68fca99113dd10162b7a161deec65a 100644 (file)
@@ -3247,7 +3247,7 @@ save_funccal(funccal_entry_T *entry)
 restore_funccal(void)
 {
     if (funccal_stack == NULL)
-       iemsg("INTERNAL: restore_funccal()");
+       internal_error("restore_funccal()");
     else
     {
        current_funccal = funccal_stack->top_funccal;
index 11e29de2025f9a55b5dcfb33bbae6ff8d2bcc09d..d9ce3d1a96352500c85c33d5258e868321055d55 100644 (file)
@@ -695,6 +695,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1576,
 /**/
     1575,
 /**/
index 926a3f348fbf818a444a5f39812f96f8884dc0c4..cc5f7df972e3d9cd7eee17e05b8973063569a638 100644 (file)
@@ -1948,7 +1948,7 @@ win_move_after(win_T *win1, win_T *win2)
     {
        if (win1->w_frame->fr_parent != win2->w_frame->fr_parent)
        {
-           iemsg("INTERNAL: trying to move a window into another frame");
+           iemsg("Trying to move a window into another frame");
            return;
        }