Skip to content

Commit cd839f4

Browse files
Add suggestions to git errors with init command
1 parent 2018e6c commit cd839f4

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

templates/cli/lib/commands/init.js.twig

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,20 @@ const initFunction = async () => {
9292
}
9393

9494
// Execute the child process but do not print any std output
95-
childProcess.execSync(gitInitCommands, { stdio: 'pipe', cwd: functionDir });
96-
97-
childProcess.execSync(gitPullCommands, { stdio: 'pipe', cwd: functionDir });
95+
try {
96+
childProcess.execSync(gitInitCommands, { stdio: 'pipe', cwd: functionDir });
97+
98+
childProcess.execSync(gitPullCommands, { stdio: 'pipe', cwd: functionDir });
99+
} catch (error) {
100+
// Specialised errors with recommended actions to take
101+
if (error.message.includes('error: unknown option `--sparse')) {
102+
throw new Error(`Error: ${error.message} \n\n Suggestion: Try updating your git to the latest version, then trying to run this command again.`)
103+
} else if (error.message.includes('is not recognized as an internal or external command,') || error.message.includes('command not found')) {
104+
throw new Error(`Error: ${error.message} \n\n Suggestion: It appears that git is not installed, try installing git then trying to run this command again.`)
105+
} else {
106+
throw error;
107+
}
108+
}
98109

99110
fs.rmSync(path.join(functionDir, ".git"), { recursive: true });
100111
const copyRecursiveSync = (src, dest) => {

0 commit comments

Comments
 (0)