Skip to content

Commit 4a39681

Browse files
chore(logging): include buffer information when logging unhandled type errors
## Details Occasionally I'll see unhandled type errors for table rows, but I have no idea what kind of tables actually produce them. To make this easier `log.unhandled` now takes a buffer id which is included in the output. Once I have the file names that cause this I'll be able to handle it. I've also updated all the log entry names to upper camel case.
1 parent df64d5d commit 4a39681

File tree

12 files changed

+33
-35
lines changed

12 files changed

+33
-35
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 NVIM v0.11.1 Last change: 2025 May 23
1+
*render-markdown.txt* For NVIM v0.11.1 Last change: 2025 May 27
22

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

lua/render-markdown/core/handlers.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,22 +53,22 @@ end
5353
---@param language string
5454
---@return render.md.Mark[]
5555
function M.tree(context, ctx, language)
56-
log.buf('debug', 'language', ctx.buf, language)
56+
log.buf('debug', 'Language', ctx.buf, language)
5757
if not context.view:overlaps(ctx.root) then
5858
return {}
5959
end
6060
local marks = {} ---@type render.md.Mark[]
6161
local custom = M.config.custom[language]
6262
if custom then
63-
log.buf('debug', 'handler', ctx.buf, 'custom')
63+
log.buf('debug', 'Handler', ctx.buf, 'custom')
6464
vim.list_extend(marks, custom.parse(ctx))
6565
if not custom.extends then
6666
return marks
6767
end
6868
end
6969
local builtin = M.builtin[language]
7070
if builtin then
71-
log.buf('debug', 'handler', ctx.buf, 'builtin')
71+
log.buf('debug', 'Handler', ctx.buf, 'builtin')
7272
vim.list_extend(marks, builtin.parse(ctx))
7373
end
7474
return marks

lua/render-markdown/core/log.lua

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,21 +74,19 @@ end
7474
---@param capture string
7575
---@param node render.md.Node
7676
function M.node(capture, node)
77-
M.add('debug', 'node', {
77+
M.add('debug', 'Node', {
7878
capture = capture,
7979
text = node.text,
8080
rows = { node.start_row, node.end_row },
8181
cols = { node.start_col, node.end_col },
8282
})
8383
end
8484

85-
---Encountered if new type is seen for a particular group
86-
---@param language string
87-
---@param group string
88-
---@param value string
89-
function M.unhandled_type(language, group, value)
90-
local message = ('%s -> %s -> %s'):format(language, group, value)
91-
M.add('error', 'unhandled type', message)
85+
---Encountered if new type is seen in a particular node
86+
---@param buf integer
87+
---@param ... string
88+
function M.unhandled(buf, ...)
89+
M.buf('error', 'UnhandledType', buf, table.concat({ ... }, ' -> '))
9290
end
9391

9492
---@param level render.md.log.Level

lua/render-markdown/core/manager.lua

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -160,23 +160,23 @@ end
160160
---@param buf integer
161161
---@return boolean
162162
function M.should_attach(buf)
163-
log.buf('info', 'attach', buf, 'start')
163+
log.buf('info', 'Attach', buf, 'start')
164164

165165
if M.attached(buf) then
166-
log.buf('info', 'attach', buf, 'skip', 'already attached')
166+
log.buf('info', 'Attach', buf, 'skip', 'already attached')
167167
return false
168168
end
169169

170170
if not vim.api.nvim_buf_is_valid(buf) then
171-
log.buf('info', 'attach', buf, 'skip', 'invalid')
171+
log.buf('info', 'Attach', buf, 'skip', 'invalid')
172172
return false
173173
end
174174

175175
local file_type = Env.buf.get(buf, 'filetype')
176176
local file_types = M.config.file_types
177177
if not vim.tbl_contains(file_types, file_type) then
178178
local reason = file_type .. ' /∈ ' .. vim.inspect(file_types)
179-
log.buf('info', 'attach', buf, 'skip', 'file type', reason)
179+
log.buf('info', 'Attach', buf, 'skip', 'file type', reason)
180180
return false
181181
end
182182

@@ -185,16 +185,16 @@ function M.should_attach(buf)
185185
local max_file_size = config.max_file_size
186186
if file_size > max_file_size then
187187
local reason = ('%f > %f'):format(file_size, max_file_size)
188-
log.buf('info', 'attach', buf, 'skip', 'file size', reason)
188+
log.buf('info', 'Attach', buf, 'skip', 'file size', reason)
189189
return false
190190
end
191191

192192
if M.config.ignore(buf) then
193-
log.buf('info', 'attach', buf, 'skip', 'user ignore')
193+
log.buf('info', 'Attach', buf, 'skip', 'user ignore')
194194
return false
195195
end
196196

197-
log.buf('info', 'attach', buf, 'success')
197+
log.buf('info', 'Attach', buf, 'success')
198198
M.buffers[#M.buffers + 1] = buf
199199
return true
200200
end

lua/render-markdown/core/ui.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ end
5050
---@param event string
5151
---@param change boolean
5252
function M.update(buf, win, event, change)
53-
log.buf('info', 'update', buf, event, ('change %s'):format(change))
53+
log.buf('info', 'Update', buf, event, ('change %s'):format(change))
5454
M.updater.new(buf, win, change):start()
5555
end
5656

@@ -119,7 +119,7 @@ function Updater:run()
119119
and self.config.resolved:render(self.mode)
120120
and not Env.win.get(self.win, 'diff')
121121
and Env.win.view(self.win).leftcol == 0
122-
log.buf('info', 'render', self.buf, render)
122+
log.buf('info', 'Render', self.buf, render)
123123
local next_state = render and 'rendered' or 'default'
124124
for _, window in ipairs(Env.buf.windows(self.buf)) do
125125
for name, value in pairs(self.config.win_options) do
@@ -163,7 +163,7 @@ end
163163
function Updater:get_extmarks()
164164
local has_parser, parser = pcall(vim.treesitter.get_parser, self.buf)
165165
if not has_parser or not parser then
166-
log.buf('error', 'fail', self.buf, 'no treesitter parser found')
166+
log.buf('error', 'Fail', self.buf, 'no treesitter parser found')
167167
return {}
168168
end
169169
-- reset buffer context

lua/render-markdown/handler/html.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function Handler:run(root)
3737
local marks = Marks.new(self.context, true)
3838
self.context.view:nodes(root, self.query, function(capture, node)
3939
local render = self.renders[capture]
40-
assert(render ~= nil, 'unhandled html capture: ' .. capture)
40+
assert(render, 'unhandled html capture: ' .. capture)
4141
render:execute(self.context, marks, node)
4242
end)
4343
return marks:get()

lua/render-markdown/handler/latex.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function Handler:run(root)
3232
return {}
3333
end
3434
if vim.fn.executable(self.config.converter) ~= 1 then
35-
log.add('debug', 'executable not found', self.config.converter)
35+
log.add('debug', 'ConverterNotFound', self.config.converter)
3636
return {}
3737
end
3838

@@ -83,7 +83,7 @@ function Handler:convert(text)
8383
local converter = self.config.converter
8484
result = vim.fn.system(converter, text)
8585
if vim.v.shell_error == 1 then
86-
log.add('error', converter, result)
86+
log.add('error', 'ConverterFailed', converter, result)
8787
result = 'error'
8888
end
8989
Handler.cache[text] = result

lua/render-markdown/handler/markdown.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ function Handler:run(root)
6363
local marks = Marks.new(self.context, false)
6464
self.context.view:nodes(root, self.query, function(capture, node)
6565
local render = self.renders[capture]
66-
assert(render ~= nil, 'unhandled markdown capture: ' .. capture)
66+
assert(render, 'unhandled markdown capture: ' .. capture)
6767
render:execute(self.context, marks, node)
6868
end)
6969
return marks:get()

lua/render-markdown/handler/markdown_inline.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function Handler:run(root)
4848
local marks = Marks.new(self.context, true)
4949
self.context.view:nodes(root, self.query, function(capture, node)
5050
local render = self.renders[capture]
51-
assert(render ~= nil, 'unhandled inline capture: ' .. capture)
51+
assert(render, 'unhandled inline capture: ' .. capture)
5252
render:execute(self.context, marks, node)
5353
end)
5454
return marks:get()

lua/render-markdown/health.lua

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

77
---@private
8-
M.version = '8.4.6'
8+
M.version = '8.4.7'
99

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

0 commit comments

Comments
 (0)