From 6d2e9c9124ecfa74ca611711760673e222f589ac Mon Sep 17 00:00:00 2001 From: Luc Chabassier Date: Fri, 29 Jul 2022 06:36:06 +0200 Subject: [PATCH] fix(logger): Fix when `stdpath('data')` doesn't exist @dwarfmaster #364 --- init.lua | 3 +++ lua/doom/utils/logging.lua | 10 +++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/init.lua b/init.lua index adfdfe83f..e4034a849 100644 --- a/init.lua +++ b/init.lua @@ -7,6 +7,9 @@ if vim.fn.has("nvim-0.6.0") ~= 1 then return end +-- Makes sure ~/.local/share/nvim exists, to prevent problems with logging +vim.fn.mkdir(vim.fn.stdpath("data"), 'p') + -- Add ~/.local/share to runtimepath early, such that -- neovim autoloads plugin/packer_compiled.lua along with vimscript, -- before we start using the plugins it lazy-loads. diff --git a/lua/doom/utils/logging.lua b/lua/doom/utils/logging.lua index 0e7c10317..a507193ad 100644 --- a/lua/doom/utils/logging.lua +++ b/lua/doom/utils/logging.lua @@ -111,9 +111,13 @@ log.new = function(config, standalone) -- Output to log file if config.use_file then local fp = io.open(outfile, "a") - local str = string.format("[%-6s%s] %s: %s\n", nameupper, os.date(), lineinfo, msg) - fp:write(str) - fp:close() + if not fp then + vim.cmd(string.format([[echom "Couldn't open log file [%s]"]], outfile)) + else + local str = string.format("[%-6s%s] %s: %s\n", nameupper, os.date(), lineinfo, msg) + fp:write(str) + fp:close() + end end end