Skip to content

Commit cfa79db

Browse files
committed
fix #3 : improve error messages and user feedback
Replace log.Fatal calls with pterm error displays for colored output
1 parent 26bac47 commit cfa79db

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

cmd/cli/createMsg.go

Lines changed: 14 additions & 8 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("Error: %v\n", err)
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,7 +56,8 @@ 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
@@ -76,7 +79,8 @@ func CreateCommitMsg () {
7679
// Get the changes
7780
changes, err := git.GetChanges(&repoConfig)
7881
if err != nil {
79-
log.Fatalf("Failed to get Git changes: %v", err)
82+
pterm.Error.Printf("Failed to get Git changes: %v\n", err)
83+
os.Exit(1)
8084
}
8185

8286
if len(changes) == 0 {
@@ -91,7 +95,8 @@ func CreateCommitMsg () {
9195
WithSequence("⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏").
9296
Start("🤖 Generating commit message...")
9397
if err != nil {
94-
log.Fatalf("Failed to start spinner: %v", err)
98+
pterm.Error.Printf("Failed to start spinner: %v\n", err)
99+
os.Exit(1)
95100
}
96101

97102
var commitMsg string
@@ -114,7 +119,8 @@ func CreateCommitMsg () {
114119

115120
if err != nil {
116121
spinnerGenerating.Fail("Failed to generate commit message")
117-
log.Fatalf("Error: %v", err)
122+
pterm.Error.Printf("Error: %v\n", err)
123+
os.Exit(1)
118124
}
119125

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

0 commit comments

Comments
 (0)