Skip to content

Commit be43b37

Browse files
committed
fix(hooks): improve error handling and logging in branch name validation
1 parent aef9cf8 commit be43b37

File tree

3 files changed

+11
-28
lines changed

3 files changed

+11
-28
lines changed

booster/.husky/commit-msg.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,18 +122,15 @@ async function validateBranchName(branchName: string): Promise<boolean> {
122122

123123
return await runTool('Branch Name', 'Validating branch name...', async () => {
124124
try {
125-
// Try quiet validation first
126125
await runWithRunner([binPath, '-t', branchName], {
127126
quiet: true,
128127
})
129-
} catch {
130-
// If failed, run again without quiet to show error
128+
} catch (error: unknown) {
131129
log.error('Branch name validation failed')
132-
try {
133-
await runWithRunner([binPath, '-t', branchName])
134-
} catch {
135-
// Error output will be shown by runWithRunner
136-
}
130+
if (typeof error === 'object' && error !== null && 'stdout' in error)
131+
console.log(error.stdout)
132+
if (typeof error === 'object' && error !== null && 'stderr' in error)
133+
console.error(error.stderr)
137134
log.info('See rules in validate-branch-name.config.cjs')
138135
throw new Error('Branch name validation failed')
139136
}

booster/.husky/shared/core.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,8 @@ export async function runWithRunner(
9191
log.info(`Executing: ${commandStr}`)
9292
}
9393

94-
// Set clean environment to avoid locale warnings
95-
const cleanEnv = {
96-
...process.env,
97-
LC_ALL: 'C',
98-
LANG: 'C',
99-
}
100-
10194
return await $({
10295
stdio: quiet ? 'pipe' : 'inherit',
103-
env: cleanEnv,
10496
})`${command}`
10597
}
10698

booster/.husky/shared/workflow.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,12 @@ export async function runQualityTools(files: string[], tools: ToolConfig[]): Pro
7171
if (filesToRun.length === 0) continue
7272

7373
// Check binary existence
74-
const binPath = tool.command
75-
let exists = false
76-
77-
try {
78-
await which(binPath)
79-
exists = true
80-
} catch {
81-
exists = false
82-
}
74+
const exists = await which(tool.command)
75+
.then(() => true)
76+
.catch(() => false)
8377

8478
if (!exists) {
85-
log.skip(`${tool.name} not found at ${binPath}. Skipping...`)
79+
log.skip(`${tool.name} not found at ${tool.command}. Skipping...`)
8680
continue
8781
}
8882

@@ -102,15 +96,15 @@ export async function runQualityTools(files: string[], tools: ToolConfig[]): Pro
10296

10397
for (const chunk of chunks) {
10498
await Promise.all(
105-
chunk.map((file) => runWithRunner([binPath, ...args, file], { quiet: true })),
99+
chunk.map((file) => runWithRunner([tool.command, ...args, file], { quiet: true })),
106100
)
107101
}
108102
} else {
109103
// Run command once with all files
110104
if (tool.passFiles !== false) {
111105
args.push(...filesToRun)
112106
}
113-
await runWithRunner([binPath, ...args])
107+
await runWithRunner([tool.command, ...args])
114108
}
115109
})
116110

0 commit comments

Comments
 (0)