Skip to content

Commit 3843ddf

Browse files
committed
fix(error-handling): add debug logging for git command failures
- Added debug namespace logging to innerDiff and innerDiffSync catch blocks - Git commands that fail now log warnings in debug mode for troubleshooting - Maintains graceful degradation behavior (returns empty array) - Helps diagnose issues with git not installed, permission problems, or non-git directories
1 parent e405e81 commit 3843ddf

1 file changed

Lines changed: 21 additions & 2 deletions

File tree

src/git.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import path from 'node:path'
22

33
import { WIN32 } from '#constants/platform'
4+
import { debugNs } from './debug'
45
import { getGlobMatcher } from './globs'
56
import { normalizePath } from './path'
67
import { spawn, spawnSync } from './spawn'
@@ -289,7 +290,16 @@ async function innerDiff(
289290
const spawnCwd =
290291
typeof args[2]['cwd'] === 'string' ? args[2]['cwd'] : undefined
291292
result = parseGitDiffStdout(stdout, parseOptions, spawnCwd)
292-
} catch {
293+
} catch (e) {
294+
// Git command failed. This is expected if:
295+
// - Not in a git repository
296+
// - Git is not installed
297+
// - Permission issues accessing .git directory
298+
// Log warning in debug mode for troubleshooting.
299+
debugNs(
300+
'git',
301+
`Git command failed (${args[0]} ${args[1].join(' ')}): ${(e as Error).message}`,
302+
)
293303
return []
294304
}
295305
if (cache && cacheKey) {
@@ -334,7 +344,16 @@ function innerDiffSync(
334344
const spawnCwd =
335345
typeof args[2]['cwd'] === 'string' ? args[2]['cwd'] : undefined
336346
result = parseGitDiffStdout(stdout, parseOptions, spawnCwd)
337-
} catch {
347+
} catch (e) {
348+
// Git command failed. This is expected if:
349+
// - Not in a git repository
350+
// - Git is not installed
351+
// - Permission issues accessing .git directory
352+
// Log warning in debug mode for troubleshooting.
353+
debugNs(
354+
'git',
355+
`Git command failed (${args[0]} ${args[1].join(' ')}): ${(e as Error).message}`,
356+
)
338357
return []
339358
}
340359
if (cache && cacheKey) {

0 commit comments

Comments
 (0)