Skip to content

Commit a9c9251

Browse files
authored
fix(utils): handle error when getting username info (#1923)
1 parent 92d1e01 commit a9c9251

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

lua/neo-tree/utils/_compat.lua

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,13 @@ local function path_resolve_dot(path)
141141
return (is_path_absolute and "/" or "") .. table.concat(new_path_components, "/")
142142
end
143143

144-
local user = uv.os_get_passwd().username
144+
local ok, passwd = pcall(uv.os_get_passwd)
145+
---@type string?
146+
local user
147+
if ok then
148+
user = passwd.username
149+
end
150+
145151
local path_segment_ends = { "/", "\\", "" }
146152
---@param path string
147153
---@param i integer
@@ -169,7 +175,7 @@ function compat.fs_normalize(path, opts)
169175

170176
if path_segment_ends_at(path, 2) then
171177
path = home .. path:sub(2)
172-
elseif vim.startswith(path, "~" .. user) and path_segment_ends_at(path, 2 + #user) then
178+
elseif user and vim.startswith(path, "~" .. user) and path_segment_ends_at(path, 2 + #user) then
173179
path = home .. path:sub(#user + 2) --- @type string
174180
end
175181
end

0 commit comments

Comments
 (0)