Skip to content

Fix build panic caused by duplicate flag registration in gp_log_collector command#6

Merged
bluethumpasaurus merged 1 commit intomasterfrom
copilot/fix-5
Sep 18, 2025
Merged

Fix build panic caused by duplicate flag registration in gp_log_collector command#6
bluethumpasaurus merged 1 commit intomasterfrom
copilot/fix-5

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Sep 18, 2025

The application was panicking on startup with panic: gp_log_collector flag redefined: failed-segs due to duplicate flag and command registration occurring in both root.go and logCollectorCmd.go init functions.

Root Cause

The issue occurred because:

  1. root.go init() was calling flagsLogCollector() and rootCmd.AddCommand(logCollectorCmd)
  2. logCollectorCmd.go init() was also calling flagsLogCollector() and rootCmd.AddCommand(logCollectorCmd)
  3. This caused all flags (including --failed-segs) to be registered twice, triggering Cobra's pflag library to panic

Solution

Removed the duplicate registration calls from root.go and followed Go's init() function best practices where each command manages its own registration completely within its own init() function. This maintains clean separation of concerns while eliminating the duplicate registration issue.

Testing

The fix has been validated with:

  • Building from scratch using the exact process described in the issue
  • Testing ./gpmt-linux-amd64 --help and ./gpmt-linux-amd64 (both previously panicked)
  • Verifying all commands work correctly: version, gp_log_collector
  • Confirming the problematic --failed-segs flag now functions properly
  • Running full validation suite (go fmt, go vet, go test)

Fixes #5.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@bluethumpasaurus bluethumpasaurus marked this pull request as ready for review September 18, 2025 12:58
@bluethumpasaurus bluethumpasaurus merged commit 1e6f9b4 into master Sep 18, 2025
1 check passed
@bluethumpasaurus bluethumpasaurus deleted the copilot/fix-5 branch September 18, 2025 12:59
Copilot AI changed the title [WIP] BUILD of Latest Code PANICS Fix build panic caused by duplicate flag registration in gp_log_collector command Sep 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUILD of Latest Code PANICS

2 participants