Skip to content

Commit 6145d22

Browse files
authored
Merge pull request #4 from adeeshperera/fix#3
fix#3 : enhance user feedback and error handling
2 parents 26bac47 + 533ee5e commit 6145d22

1 file changed

Lines changed: 35 additions & 10 deletions

File tree

cmd/cli/createMsg.go

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package cmd
22

33
import (
4-
"log"
54
"os"
65

76
"github.com/atotto/clipboard"
@@ -23,7 +22,8 @@ func CreateCommitMsg () {
2322
// Validate COMMIT_LLM and required API keys
2423
useLLM,err := store.DefaultLLMKey()
2524
if err != nil {
26-
log.Fatal(err)
25+
pterm.Error.Printf("No LLM configured. Run: commit llm setup\n")
26+
os.Exit(1)
2727
}
2828

2929
commitLLM := useLLM.LLM
@@ -33,12 +33,14 @@ func CreateCommitMsg () {
3333
// Get current directory
3434
currentDir, err := os.Getwd()
3535
if err != nil {
36-
log.Fatalf("Failed to get current directory: %v", err)
36+
pterm.Error.Printf("Failed to get current directory: %v\n", err)
37+
os.Exit(1)
3738
}
3839

3940
// Check if current directory is a git repository
4041
if !git.IsRepository(currentDir) {
41-
log.Fatalf("Current directory is not a Git repository: %s", currentDir)
42+
pterm.Error.Printf("Current directory is not a Git repository: %s\n", currentDir)
43+
os.Exit(1)
4244
}
4345

4446
// Create a minimal config for the API
@@ -54,14 +56,15 @@ func CreateCommitMsg () {
5456
// Get file statistics before fetching changes
5557
fileStats, err := stats.GetFileStatistics(&repoConfig)
5658
if err != nil {
57-
log.Fatalf("Failed to get file statistics: %v", err)
59+
pterm.Error.Printf("Failed to get file statistics: %v\n", err)
60+
os.Exit(1)
5861
}
5962

6063
// Display header
6164
pterm.DefaultHeader.WithFullWidth().
6265
WithBackgroundStyle(pterm.NewStyle(pterm.BgDarkGray)).
6366
WithTextStyle(pterm.NewStyle(pterm.FgLightWhite)).
64-
Println("🚀 Commit Message Generator")
67+
Println("Commit Message Generator")
6568

6669
pterm.Println()
6770

@@ -70,17 +73,26 @@ func CreateCommitMsg () {
7073

7174
if fileStats.TotalFiles == 0 {
7275
pterm.Warning.Println("No changes detected in the Git repository.")
76+
pterm.Info.Println("Tips:")
77+
pterm.Info.Println(" - Stage your changes with: git add .")
78+
pterm.Info.Println(" - Check repository status with: git status")
79+
pterm.Info.Println(" - Make sure you're in the correct Git repository")
7380
return
7481
}
7582

7683
// Get the changes
7784
changes, err := git.GetChanges(&repoConfig)
7885
if err != nil {
79-
log.Fatalf("Failed to get Git changes: %v", err)
86+
pterm.Error.Printf("Failed to get Git changes: %v\n", err)
87+
os.Exit(1)
8088
}
8189

8290
if len(changes) == 0 {
8391
pterm.Warning.Println("No changes detected in the Git repository.")
92+
pterm.Info.Println("Tips:")
93+
pterm.Info.Println(" - Stage your changes with: git add .")
94+
pterm.Info.Println(" - Check repository status with: git status")
95+
pterm.Info.Println(" - Make sure you're in the correct Git repository")
8496
return
8597
}
8698

@@ -89,9 +101,10 @@ func CreateCommitMsg () {
89101
// Show generating spinner
90102
spinnerGenerating, err := pterm.DefaultSpinner.
91103
WithSequence("⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏").
92-
Start("🤖 Generating commit message...")
104+
Start("Generating commit message with " + commitLLM + "...")
93105
if err != nil {
94-
log.Fatalf("Failed to start spinner: %v", err)
106+
pterm.Error.Printf("Failed to start spinner: %v\n", err)
107+
os.Exit(1)
95108
}
96109

97110
var commitMsg string
@@ -114,7 +127,19 @@ func CreateCommitMsg () {
114127

115128
if err != nil {
116129
spinnerGenerating.Fail("Failed to generate commit message")
117-
log.Fatalf("Error: %v", err)
130+
switch commitLLM {
131+
case "Gemini":
132+
pterm.Error.Printf("Gemini API error. Check your GEMINI_API_KEY environment variable or run: commit llm setup\n")
133+
case "OpenAI":
134+
pterm.Error.Printf("OpenAI API error. Check your OPENAI_API_KEY environment variable or run: commit llm setup\n")
135+
case "Claude":
136+
pterm.Error.Printf("Claude API error. Check your CLAUDE_API_KEY environment variable or run: commit llm setup\n")
137+
case "Grok":
138+
pterm.Error.Printf("Grok API error. Check your GROK_API_KEY environment variable or run: commit llm setup\n")
139+
default:
140+
pterm.Error.Printf("LLM API error: %v\n", err)
141+
}
142+
os.Exit(1)
118143
}
119144

120145
spinnerGenerating.Success("✅ Commit message generated successfully!")

0 commit comments

Comments
 (0)