Skip to content

Commit 69f5a63

Browse files
committed
Use a pcall to prevent an error being raised
1 parent fbfa65b commit 69f5a63

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

lua/nvim-tree/marks/init.lua

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,12 @@ local function save_bookmarks(marks, opts)
2727
for path, _ in pairs(marks) do
2828
table.insert(data, path)
2929
end
30-
print(storepath)
3130
file:write(vim.json.encode(data))
3231
file:close()
3332
end
3433
end
3534

3635
local function load_bookmarks(opts)
37-
if not opts.marks.enable_persistence then
38-
return {}
39-
end
4036
local storepath = get_save_path(opts)
4137
local file = io.open(storepath, "r")
4238
if file then
@@ -69,7 +65,15 @@ local Marks = Class:extend()
6965
---@param args MarksArgs
7066
function Marks:new(args)
7167
self.explorer = args.explorer
72-
self.marks = load_bookmarks(self.explorer.opts) or {}
68+
self.marks = {}
69+
if self.explorer.opts.marks.enable_persistence then
70+
local ok, loaded_marks = pcall(load_bookmarks, self.explorer.opts)
71+
if ok then
72+
self.marks = loaded_marks
73+
else
74+
notify.warn("Failed to load bookmarks: " .. loaded_marks)
75+
end
76+
end
7377
end
7478

7579
---Clear all marks and reload if watchers disabled
@@ -100,7 +104,13 @@ function Marks:toggle(node)
100104
else
101105
self.marks[node.absolute_path] = node
102106
end
103-
save_bookmarks(self.marks, self.explorer.opts)
107+
108+
if self.explorer.opts.marks.enable_persistence then
109+
local ok, err = pcall(save_bookmarks, self.marks, self.explorer.opts)
110+
if not ok then
111+
notify.warn("Failed to save bookmarks: " .. err)
112+
end
113+
end
104114
self.explorer.renderer:draw()
105115
end
106116

0 commit comments

Comments
 (0)