Skip to content

Conversation

@adeeshperera
Copy link
Contributor

@adeeshperera adeeshperera commented Oct 5, 2025

  • Replace log.Fatal calls with pterm error displays for better colored output
  • Add actionable error messages for missing API keys with setup instructions
  • Display LLM provider name in progress spinner for better visibility
  • Show helpful tips when no Git changes are detected

Summary by CodeRabbit

  • New Features

    • Clearer, user-friendly error messages with guidance for LLM setup and environment variables.
    • Helpful tips when no changes are detected in the repository.
    • Spinner now displays the selected model during commit message generation.
  • Style

    • Updated header to “Commit Message Generator” for a cleaner presentation.
    • Harmonized on-screen messaging for a more consistent CLI experience.

adeeshperera and others added 6 commits October 6, 2025 00:22
Replace log.Fatal calls with pterm error displays for colored output
Add specific instructions for setting environment variables when API keys are missing
Update spinner message to display which LLM (Gemini, OpenAI, Claude, Grok) is being used
Display actionable guidance for staging changes, checking status, and verifying repository location
fix#3 : enhance user feedback and error handling
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 5, 2025

Walkthrough

Replaces log.Fatal usage with pterm error/info outputs and explicit os.Exit(1) across error paths, updates header text, adds guidance when no changes are detected, customizes spinner message with selected LLM, and introduces per-LLM API failure guidance. Core logic for config, repo, stats, changes, and message generation remains unchanged.

Changes

Cohort / File(s) Summary
CLI error handling and UX updates
cmd/cli/createMsg.go
Replaced log.Fatal/log.Fatalf with pterm.Error.Printf and os.Exit(1); removed log import. Added pterm.Info tips for no-change scenarios. Updated header to "Commit Message Generator". Spinner start text now includes selected LLM name. Added per-LLM API failure guidance referencing env vars/setup. Core fetch/generation flow unchanged.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant U as User
  participant CLI as CLI (createMsg)
  participant Repo as Git Repo
  participant LLM as LLM Provider

  U->>CLI: Run commit message generator
  CLI->>CLI: Load config (LLM, repo)
  alt Config error
    CLI-->>U: pterm.Error (check setup) + exit(1)
  end

  CLI->>Repo: Get current dir, ensure repo
  alt Not a repo / dir error
    CLI-->>U: pterm.Error + exit(1)
  end

  CLI->>Repo: Collect file stats and changes
  alt No changes
    CLI-->>U: pterm.Info (nothing to commit) + exit(0/return)
  end

  CLI->>CLI: Start spinner ("Generating via <LLM>")
  CLI->>LLM: Generate commit message
  alt LLM/API error
    CLI-->>U: pterm.Error (per-LLM env vars/setup) + exit(1)
  else Success
    CLI-->>U: Show generated message
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I thump my paws on terminal ground,
Swap fatal logs for friendlier sound.
A spinner twirls, the LLM’s named—
If errors hop, they’re neatly framed.
No changes? Cool—I'll nibble hay.
Commit words bloom another day.
— a cheerful code rabbit 🐇✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly conveys the main purpose of the changeset—enhancing user feedback and error handling—and accurately reflects the updates described in the pull request, including improved messaging and guidance; although it references issue #3, it remains clear and directly related to the implemented functionality.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Comment @coderabbitai help to get the list of available commands and usage tips.

@DFanso DFanso linked an issue Oct 5, 2025 that may be closed by this pull request
@DFanso DFanso self-requested a review October 5, 2025 19:39
@adeeshperera adeeshperera changed the title fix#3 : enhance user feedback and error handling fix #3 : enhance user feedback and error handling Oct 5, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
cmd/cli/createMsg.go (2)

77-80: Extract duplicate tip messages to a helper function.

The same four tip lines are repeated in two locations (lines 77-80 and 93-96). While these handle slightly different scenarios (no files tracked vs. no changes detected), the guidance is identical.

Consider extracting to a helper function:

+func showNoChangesGuidance() {
+	pterm.Info.Println("Tips:")
+	pterm.Info.Println("  - Stage your changes with: git add .")
+	pterm.Info.Println("  - Check repository status with: git status")
+	pterm.Info.Println("  - Make sure you're in the correct Git repository")
+}

Then replace both occurrences:

 	if fileStats.TotalFiles == 0 {
 		pterm.Warning.Println("No changes detected in the Git repository.")
-		pterm.Info.Println("Tips:")
-		pterm.Info.Println("  - Stage your changes with: git add .")
-		pterm.Info.Println("  - Check repository status with: git status")
-		pterm.Info.Println("  - Make sure you're in the correct Git repository")
+		showNoChangesGuidance()
 		return
 	}
 	if len(changes) == 0 {
 		pterm.Warning.Println("No changes detected in the Git repository.")
-		pterm.Info.Println("Tips:")
-		pterm.Info.Println("  - Stage your changes with: git add .")
-		pterm.Info.Println("  - Check repository status with: git status")
-		pterm.Info.Println("  - Make sure you're in the correct Git repository")
+		showNoChangesGuidance()
 		return
 	}

Also applies to: 93-96


142-154: Align error handling switch with generation switch.

The generation switch (lines 113-137) uses default for Grok, but this error handling switch has an explicit "Grok" case. If commitLLM contains an unexpected value, the code will call the Grok API (via default) but display a generic error message (via default here).

For consistency, add an explicit "Grok" case to the generation switch:

 	case "Ollama":
 		url := os.Getenv("OLLAMA_URL")
 		if url == "" {
 			url = "http://localhost:11434/api/generate"
 		}
 		model := os.Getenv("OLLAMA_MODEL")
 		if model == "" {
 			model = "llama3:latest"
 		}
 		commitMsg, err = ollama.GenerateCommitMessage(config, changes, url, model)
 
+	case "Grok":
+		commitMsg, err = grok.GenerateCommitMessage(config, changes, apiKey)
 
 	default:
-		commitMsg, err = grok.GenerateCommitMessage(config, changes, apiKey)
+		pterm.Error.Printf("Unknown LLM: %s\n", commitLLM)
+		os.Exit(1)
 	}

This ensures consistent behavior: unknown LLM values fail fast rather than silently defaulting to Grok.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ea6774b and 18f786f.

📒 Files selected for processing (1)
  • cmd/cli/createMsg.go (6 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
cmd/cli/createMsg.go (1)
internal/git/operations.go (2)
  • IsRepository (16-23)
  • GetChanges (26-130)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Package Binaries
🔇 Additional comments (3)
cmd/cli/createMsg.go (3)

26-27: LGTM! Clear and actionable error message.

The replacement of log.Fatal with pterm.Error.Printf and explicit os.Exit(1) provides better visual feedback to users with colored output and a clear setup instruction.


37-38: LGTM! Consistent error handling pattern.

The uniform replacement of log.Fatal with pterm.Error.Printf and explicit os.Exit(1) across all error paths provides consistent, user-friendly error messaging with colored output.

Also applies to: 43-44, 60-61, 87-88, 107-108


105-105: LGTM! Enhanced user visibility.

Dynamically including the LLM name in the spinner message provides better transparency about which provider is generating the commit message.

@DFanso DFanso added enhancement New feature or request hacktoberfest Eligible for Hacktoberfest hacktoberfest-accepted Approved Hacktoberfest contribution go Pull requests that update go code labels Oct 5, 2025
Copy link
Owner

@DFanso DFanso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved 🎊

@DFanso DFanso merged commit 57729f5 into DFanso:main Oct 5, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request go Pull requests that update go code hacktoberfest Eligible for Hacktoberfest hacktoberfest-accepted Approved Hacktoberfest contribution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Enhancement] Improve Error Messages and User Feedback

2 participants