Skip to content

Commit 6a7bc88

Browse files
committed
refactor(cli): improve error messages
1 parent 3992c57 commit 6a7bc88

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/commands/install.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,24 @@ import path from 'path'
44

55
import { l } from '../log'
66

7+
const customDirHelp = 'https://typicode.github.io/husky/#/?id=custom-directory'
8+
79
export function install(dir = '.husky'): void {
810
// Ensure that we're inside a git repository
911
if (cp.spawnSync('git', ['rev-parse']).status !== 0) {
10-
// Do not fail to let projects downloaded as zip files have their dependencies installed
1112
l('not a Git repository, skipping hooks installation')
1213
return
1314
}
1415

15-
// Ensure that we're not trying to install outside cwd
16+
// Ensure that we're not trying to install outside of cwd
1617
const absoluteHooksDir = path.resolve(process.cwd(), dir)
1718
if (!absoluteHooksDir.startsWith(process.cwd())) {
18-
throw new Error('.. not allowed')
19+
throw new Error(`.. not allowed (see ${customDirHelp})`)
1920
}
2021

2122
// Ensure that cwd is git top level
2223
if (!fs.existsSync('.git')) {
23-
throw new Error(".git can't be found")
24+
throw new Error(`.git can't be found (see ${customDirHelp})`)
2425
}
2526

2627
try {

src/commands/set_add.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ function format(file: string): string {
1919
export function set(file: string, cmd: string): void {
2020
const dir = path.dirname(file)
2121
if (!fs.existsSync(dir)) {
22-
throw new Error(`can't create hook, ${dir} directory doesn't exist`)
22+
throw new Error(
23+
`can't create hook, ${dir} directory doesn't exist (try running husky install)`,
24+
)
2325
}
2426

2527
fs.writeFileSync(file, data(cmd), { mode: 0o0755 })

0 commit comments

Comments
 (0)