Skip to content

Commit 0022a57

Browse files
fix: check buffer is valid when getting name
## Details Issue: #260 When logging info at the buffer level we get the file name for the buffer to make the logs more useful. However if the buffer is invalid this call to get file name will throw an exception. Wrap the call to get file name in a check that buffer is valid. Return some default string if it is not. Other parts of the ui.update flow will validate the buffer and window and prevent any actual changes to invalid buffers.
1 parent e41b000 commit 0022a57

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

doc/render-markdown.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*render-markdown.txt* For 0.10.0 Last change: 2024 December 09
1+
*render-markdown.txt* For 0.10.0 Last change: 2024 December 13
22

33
==============================================================================
44
Table of Contents *render-markdown-table-of-contents*

lua/render-markdown/core/util.lua

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,12 @@ end
128128
---@param buf integer
129129
---@return string
130130
function M.file_name(buf)
131-
local file = vim.api.nvim_buf_get_name(buf)
132-
return vim.fn.fnamemodify(file, ':t')
131+
if vim.api.nvim_buf_is_valid(buf) then
132+
local file = vim.api.nvim_buf_get_name(buf)
133+
return vim.fn.fnamemodify(file, ':t')
134+
else
135+
return 'INVALID'
136+
end
133137
end
134138

135139
---@param source string|integer

lua/render-markdown/health.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ local state = require('render-markdown.state')
44
local M = {}
55

66
---@private
7-
M.version = '7.7.3'
7+
M.version = '7.7.4'
88

99
function M.check()
1010
M.start('version')

0 commit comments

Comments
 (0)