Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion lua/vibing/application/daily_summary/collector.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,24 @@ function M.find_vibing_files(directory, opts)
local vibing_files, err1 = finder:find(directory, "*.vibing")
local md_files, err2 = finder:find(directory, "*.md")

if err1 and err2 then
-- Warn about errors but continue with partial results
-- If both searches completely failed with no results, return empty
local has_results = (vibing_files and #vibing_files > 0) or (md_files and #md_files > 0)
if err1 and err2 and not has_results then
vim.notify(
string.format("vibing.nvim: Failed to search directory %s: %s", directory, err1),
vim.log.levels.WARN
)
return {}
end
-- Warn about partial errors (permission denied on some subdirectories)
local partial_err = err1 or err2
if partial_err and has_results then
vim.notify(
string.format("vibing.nvim: Partial error searching directory %s: %s", directory, partial_err),
vim.log.levels.WARN
)
end
Comment on lines +22 to +39
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Silent failure when exactly one search errors and neither returns results.

The current condition if partial_err and has_results means a warning is only emitted when there are results plus a partial error. When one search completely fails (e.g., err1 = "rg command failed: …") and the other succeeds with zero results (err2 = nil, md_files = {}), all three conditions evaluate as:

variable value
has_results false
err1 and err2 and not has_results false (err2 is nil) → no early abort
partial_err and has_results falseno warning

The function returns {} silently. The user sees "no files found" with no diagnostic, masking a real error in one of the two finders.

🐛 Proposed fix — always warn when any error is present
-  -- Warn about partial errors (permission denied on some subdirectories)
-  local partial_err = err1 or err2
-  if partial_err and has_results then
-    vim.notify(
-      string.format("vibing.nvim: Partial error searching directory %s: %s", directory, partial_err),
-      vim.log.levels.WARN
-    )
-  end
+  -- Warn about partial errors (permission denied on some subdirectories)
+  -- or when one search failed outright while the other returned nothing
+  local partial_err = err1 or err2
+  if partial_err then
+    vim.notify(
+      string.format("vibing.nvim: Partial error searching directory %s: %s", directory, partial_err),
+      vim.log.levels.WARN
+    )
+  end

Note: This makes the early-abort block above (which already notifies and returns {}) the only path that suppresses the partial warning — specifically when both searches fail with no results. All other error states will emit a diagnostic.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
-- Warn about errors but continue with partial results
-- If both searches completely failed with no results, return empty
local has_results = (vibing_files and #vibing_files > 0) or (md_files and #md_files > 0)
if err1 and err2 and not has_results then
vim.notify(
string.format("vibing.nvim: Failed to search directory %s: %s", directory, err1),
vim.log.levels.WARN
)
return {}
end
-- Warn about partial errors (permission denied on some subdirectories)
local partial_err = err1 or err2
if partial_err and has_results then
vim.notify(
string.format("vibing.nvim: Partial error searching directory %s: %s", directory, partial_err),
vim.log.levels.WARN
)
end
-- Warn about errors but continue with partial results
-- If both searches completely failed with no results, return empty
local has_results = (vibing_files and `#vibing_files` > 0) or (md_files and `#md_files` > 0)
if err1 and err2 and not has_results then
vim.notify(
string.format("vibing.nvim: Failed to search directory %s: %s", directory, err1),
vim.log.levels.WARN
)
return {}
end
-- Warn about partial errors (permission denied on some subdirectories)
-- or when one search failed outright while the other returned nothing
local partial_err = err1 or err2
if partial_err then
vim.notify(
string.format("vibing.nvim: Partial error searching directory %s: %s", directory, partial_err),
vim.log.levels.WARN
)
end
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lua/vibing/application/daily_summary/collector.lua` around lines 22 - 39, The
current logic misses emitting a warning when exactly one search errors but
neither returns results; change the partial-warning branch to notify whenever
any error exists (partial_err) instead of requiring has_results, since the
earlier block already handles the case where both searches failed with no
results (err1 and err2 and not has_results) and returns. Update the condition
around the vim.notify call that currently checks partial_err and has_results to
simply check partial_err (ref: err1, err2, has_results, partial_err in
collector.lua) so any single-search error produces a diagnostic.


local all_files = vim.list_extend(vibing_files or {}, md_files or {})

Expand Down
22 changes: 19 additions & 3 deletions lua/vibing/infrastructure/file_finder/fd_command.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,33 @@ local Base = require("vibing.infrastructure.file_finder.base")
local FdCommand = setmetatable({}, { __index = Base })
FdCommand.__index = FdCommand

---Detect fd executable name (fd or fdfind on Ubuntu/Debian)
---@return string? executable name or nil if not found
local function detect_fd_executable()
for _, name in ipairs({ "fd", "fdfind" }) do
local result = vim.system({ "which", name }, { text = true }):wait()
if result.code == 0 then
return name
end
end
return nil
end

---Create a FdCommandFinder instance
---@param opts? {mtime_days?: number} Options for finder
---@return Vibing.Infrastructure.FdCommandFinder
function FdCommand:new(opts)
local instance = setmetatable({}, self)
instance.name = "fd_command"
instance.mtime_days = opts and opts.mtime_days
instance.executable = detect_fd_executable()
return instance
end

---Check if fd command is available
---@return boolean
function FdCommand:supports_platform()
local result = vim.system({ "which", "fd" }, { text = true }):wait()
return result.code == 0
return self.executable ~= nil
end

---Extract extension from glob pattern (e.g., "*.md" -> "md")
Expand All @@ -44,6 +56,10 @@ function FdCommand:find(directory, pattern)

local expanded_dir = vim.fn.expand(directory)

if not self.executable then
return {}, "fd command not available"
end

-- Build fd command
-- fd [OPTIONS] [pattern] [path]
-- -t f: files only
Expand All @@ -52,7 +68,7 @@ function FdCommand:find(directory, pattern)
-- --no-ignore: don't respect .gitignore (we want all chat files)
-- --no-follow: don't follow symlinks (prevents circular reference)
local cmd = {
"fd",
self.executable,
"-t", "f",
"-a",
"-H",
Expand Down
17 changes: 14 additions & 3 deletions lua/vibing/infrastructure/file_finder/ripgrep_command.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,22 @@ function RipgrepCommand:find(directory, pattern)

local result = vim.system(cmd, { text = true }):wait()

-- rg returns 1 when no matches found (not an error)
if result.code ~= 0 and result.code ~= 1 then
-- rg returns:
-- 0: matches found
-- 1: no matches found (not an error)
-- 2: error occurred (e.g. permission denied), but may still have partial stdout results
if result.code ~= 0 and result.code ~= 1 and result.code ~= 2 then
return {}, "rg command failed: " .. (result.stderr or "unknown error")
end

-- For exit code 2 (e.g. Permission denied), return partial results with a warning error
local partial_error = nil
if result.code == 2 and result.stderr and result.stderr ~= "" then
-- Extract first line of stderr for a concise warning message
local first_error = result.stderr:match("([^\n]+)") or result.stderr
partial_error = "rg command failed: " .. first_error
end

local files = {}
if result.stdout and result.stdout ~= "" then
for line in result.stdout:gmatch("[^\r\n]+") do
Expand All @@ -79,7 +90,7 @@ function RipgrepCommand:find(directory, pattern)
end
end

return files, nil
return files, partial_error
end

return RipgrepCommand
Loading