Skip to content

Commit 38e8717

Browse files
authored
fix: handle missing stats gracefully in file detail columns (#1118)
1 parent 70ab62c commit 38e8717

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

lua/neo-tree/sources/common/components.lua

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -451,11 +451,16 @@ M.file_size = function (config, node, state)
451451
}
452452
end
453453

454-
local stat = utils.get_stat(node)
455454
local text = "-"
456455
if node.type == "file" then
456+
local stat = utils.get_stat(node)
457457
local size = stat and stat.size or nil
458-
text = utils.filesize(size) or text
458+
if size then
459+
local success, human = pcall(utils.filesize, size)
460+
if success then
461+
text = human or text
462+
end
463+
end
459464
end
460465

461466
return {
@@ -482,9 +487,9 @@ local file_time = function(config, node, state, stat_field)
482487
local stat = utils.get_stat(node)
483488
local value = stat and stat[stat_field]
484489
local seconds = value and value.sec or nil
485-
local as_date = seconds and os.date("%Y-%m-%d %I:%M %p ", seconds) or nil
490+
local display = seconds and os.date("%Y-%m-%d %I:%M %p", seconds) or "-"
486491
return {
487-
text = as_date and string.format(" %s", as_date) or "",
492+
text = string.format("%20s ", display),
488493
highlight = config.highlight or highlights.FILE_STATS
489494
}
490495
end

0 commit comments

Comments
 (0)