aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2024-11-13 13:22:40 +0800
committerGitHub <noreply@github.com>2024-11-13 13:22:40 +0800
commit17e00d0cc63cf2a42a66b03f28bd567f11998c24 (patch)
treeab27dfad6c411fd3cc81a8d75d3419d0f932a5cb
parent1128d75550fa0b481b8953a194bae890d733a166 (diff)
downloadrneovim-17e00d0cc63cf2a42a66b03f28bd567f11998c24.tar.gz
rneovim-17e00d0cc63cf2a42a66b03f28bd567f11998c24.tar.bz2
rneovim-17e00d0cc63cf2a42a66b03f28bd567f11998c24.zip
fix(startup): report --startuptime error to stderr (#31131)
Problem: Crash when initializing for --startuptime errors. Solution: Report the error to stderr, as neither logging nor messages have been initialized yet.
-rw-r--r--src/nvim/profile.c5
-rw-r--r--test/functional/core/startup_spec.lua19
2 files changed, 21 insertions, 3 deletions
diff --git a/src/nvim/profile.c b/src/nvim/profile.c
index 81207b4e39..1b4f4a2029 100644
--- a/src/nvim/profile.c
+++ b/src/nvim/profile.c
@@ -956,7 +956,7 @@ void time_init(const char *fname, const char *proc_name)
const size_t bufsize = 8192; // Big enough for the entire --startuptime report.
time_fd = fopen(fname, "a");
if (time_fd == NULL) {
- semsg(_(e_notopen), fname);
+ fprintf(stderr, _(e_notopen), fname);
return;
}
startuptime_buf = xmalloc(sizeof(char) * (bufsize + 1));
@@ -968,8 +968,7 @@ void time_init(const char *fname, const char *proc_name)
XFREE_CLEAR(startuptime_buf);
fclose(time_fd);
time_fd = NULL;
- ELOG("time_init: setvbuf failed: %d %s", r, uv_err_name(r));
- semsg("time_init: setvbuf failed: %d %s", r, uv_err_name(r));
+ fprintf(stderr, "time_init: setvbuf failed: %d %s", r, uv_err_name(r));
return;
}
fprintf(time_fd, "--- Startup times for process: %s ---\n", proc_name);
diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua
index f48bcb9360..7f99a4a2eb 100644
--- a/test/functional/core/startup_spec.lua
+++ b/test/functional/core/startup_spec.lua
@@ -74,6 +74,25 @@ describe('startup', function()
assert_log("require%('vim%._editor'%)", testfile, 100)
end)
+ it('--startuptime does not crash on error #31125', function()
+ eq(
+ "E484: Can't open file .",
+ fn.system({
+ nvim_prog,
+ '-u',
+ 'NONE',
+ '-i',
+ 'NONE',
+ '--headless',
+ '--startuptime',
+ '.',
+ '-c',
+ '42cquit',
+ })
+ )
+ eq(42, api.nvim_get_vvar('shell_error'))
+ end)
+
it('-D does not hang #12647', function()
clear()
local screen