Skip to content

Commit 1a4c20a

Browse files
authored
fix(tangle): proper error handling for fs_close (#1647)
Currently the lack of error handing causes a bad file descriptor error, which results in empty tangled files.
1 parent ec4efa4 commit 1a4c20a

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

lua/neorg/modules/core/tangle/module.lua

+5-3
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ module.on_event = function(event)
506506
file:parent():mkdir(Path.permission("rwxr-xr-x"), true)
507507
end
508508
file = file:tostring()
509-
vim.loop.fs_open(file, "w", 438, function(err, fd)
509+
vim.uv.fs_open(file, "w", 438, function(err, fd)
510510
assert(not err and fd, lib.lazy_string_concat("Failed to open file '", file, "' for tangling: ", err))
511511

512512
local write_content = table.concat(content, "\n")
@@ -516,7 +516,7 @@ module.on_event = function(event)
516516
end)
517517
end
518518

519-
vim.loop.fs_write(fd, write_content, 0, function(werr)
519+
vim.uv.fs_write(fd, write_content, 0, function(werr)
520520
assert(not werr, lib.lazy_string_concat("Failed to write to '", file, "' for tangling: ", werr))
521521
tangled_count = tangled_count + 1
522522
file_count = file_count - 1
@@ -533,7 +533,9 @@ module.on_event = function(event)
533533
)
534534
end
535535
end)
536-
vim.uv.fs_close(fd)
536+
vim.uv.fs_close(fd, function(err)
537+
assert(not err, lib.lazy_string_concat("Failed to close file '", file, "' for tangling: ", err))
538+
end)
537539
end)
538540
::continue::
539541
end

0 commit comments

Comments
 (0)