Skip to content

Commit 671771b

Browse files
Add debug logging to 5 key Go files for improved troubleshooting (#2681)
1 parent 4168621 commit 671771b

5 files changed

Lines changed: 41 additions & 0 deletions

File tree

pkg/cli/interactive.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ import (
1010
"github.com/charmbracelet/huh"
1111
"github.com/githubnext/gh-aw/pkg/console"
1212
"github.com/githubnext/gh-aw/pkg/constants"
13+
"github.com/githubnext/gh-aw/pkg/logger"
1314
)
1415

16+
var interactiveLog = logger.New("cli:interactive")
17+
1518
// InteractiveWorkflowBuilder collects user input to build an agentic workflow
1619
type InteractiveWorkflowBuilder struct {
1720
WorkflowName string
@@ -26,6 +29,8 @@ type InteractiveWorkflowBuilder struct {
2629

2730
// CreateWorkflowInteractively prompts the user to build a workflow interactively
2831
func CreateWorkflowInteractively(workflowName string, verbose bool, force bool) error {
32+
interactiveLog.Printf("Starting interactive workflow creation: workflowName=%s, force=%v", workflowName, force)
33+
2934
// Assert this function is not running in automated unit tests
3035
if os.Getenv("GO_TEST_MODE") == "true" || os.Getenv("CI") != "" {
3136
return fmt.Errorf("interactive workflow creation cannot be used in automated tests or CI environments")
@@ -247,6 +252,8 @@ func (b *InteractiveWorkflowBuilder) promptForIntent() error {
247252

248253
// generateWorkflow creates the markdown workflow file based on user selections
249254
func (b *InteractiveWorkflowBuilder) generateWorkflow(force bool) error {
255+
interactiveLog.Printf("Generating workflow file: name=%s, engine=%s, trigger=%s", b.WorkflowName, b.Engine, b.Trigger)
256+
250257
// Get current working directory for .github/workflows
251258
workingDir, err := os.Getwd()
252259
if err != nil {
@@ -275,6 +282,7 @@ func (b *InteractiveWorkflowBuilder) generateWorkflow(force bool) error {
275282
return fmt.Errorf("failed to write workflow file '%s': %w", destFile, err)
276283
}
277284

285+
interactiveLog.Printf("Workflow file created successfully: %s", destFile)
278286
fmt.Fprintf(os.Stderr, "Created new workflow: %s\n", destFile)
279287
return nil
280288
}

pkg/cli/logs.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,15 @@ import (
1616

1717
"github.com/githubnext/gh-aw/pkg/console"
1818
"github.com/githubnext/gh-aw/pkg/constants"
19+
"github.com/githubnext/gh-aw/pkg/logger"
1920
"github.com/githubnext/gh-aw/pkg/workflow"
2021
"github.com/githubnext/gh-aw/pkg/workflow/pretty"
2122
"github.com/sourcegraph/conc/pool"
2223
"github.com/spf13/cobra"
2324
)
2425

26+
var logsLog = logger.New("cli:logs")
27+
2528
const (
2629
// defaultAgentStdioLogPath is the default log file path for agent stdout/stderr
2730
defaultAgentStdioLogPath = "/tmp/gh-aw/agent-stdio.log"
@@ -130,6 +133,7 @@ type RunSummary struct {
130133

131134
// fetchJobStatuses gets job information for a workflow run and counts failed jobs
132135
func fetchJobStatuses(runID int64, verbose bool) (int, error) {
136+
logsLog.Printf("Fetching job statuses: runID=%d", runID)
133137
args := []string{"api", fmt.Sprintf("repos/{owner}/{repo}/actions/runs/%d/jobs", runID), "--jq", ".jobs[] | {name: .name, status: .status, conclusion: .conclusion}"}
134138

135139
if verbose {
@@ -165,12 +169,14 @@ func fetchJobStatuses(runID int64, verbose bool) (int, error) {
165169
// Count jobs with failure conclusions as errors
166170
if job.Conclusion == "failure" || job.Conclusion == "cancelled" || job.Conclusion == "timed_out" {
167171
failedJobs++
172+
logsLog.Printf("Found failed job: name=%s, conclusion=%s", job.Name, job.Conclusion)
168173
if verbose {
169174
fmt.Println(console.FormatVerboseMessage(fmt.Sprintf("Found failed job '%s' with conclusion '%s'", job.Name, job.Conclusion)))
170175
}
171176
}
172177
}
173178

179+
logsLog.Printf("Job status check complete: failedJobs=%d", failedJobs)
174180
return failedJobs, nil
175181
}
176182

@@ -436,6 +442,7 @@ Examples:
436442

437443
// DownloadWorkflowLogs downloads and analyzes workflow logs with metrics
438444
func DownloadWorkflowLogs(workflowName string, count int, startDate, endDate, outputDir, engine, branch string, beforeRunID, afterRunID int64, verbose bool, toolGraph bool, noStaged bool, parse bool, jsonOutput bool, timeout int) error {
445+
logsLog.Printf("Starting workflow log download: workflow=%s, count=%d, startDate=%s, endDate=%s, outputDir=%s", workflowName, count, startDate, endDate, outputDir)
439446
if verbose {
440447
fmt.Fprintln(os.Stderr, console.FormatInfoMessage("Fetching workflow runs from GitHub Actions..."))
441448
}
@@ -785,6 +792,7 @@ func downloadRunArtifactsConcurrent(runs []WorkflowRun, outputDir string, verbos
785792
// Limit the number of runs to process if maxRuns is specified
786793
actualRuns := runs
787794
if maxRuns > 0 && len(runs) > maxRuns {
795+
logsLog.Printf("Limiting concurrent downloads: maxRuns=%d, totalRuns=%d", maxRuns, len(runs))
788796
actualRuns = runs[:maxRuns]
789797
}
790798

pkg/cli/secrets.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@ import (
88
"regexp"
99
"strings"
1010

11+
"github.com/githubnext/gh-aw/pkg/logger"
1112
"github.com/githubnext/gh-aw/pkg/parser"
1213
)
1314

15+
var secretsLog = logger.New("cli:secrets")
16+
1417
// Pre-compiled regexes for secret extraction (performance optimization)
1518
var (
1619
secretPattern = regexp.MustCompile(`\$\{\{\s*secrets\.([A-Z_][A-Z0-9_]*)\s*(?:\|\|.*?)?\s*\}\}`)
@@ -27,6 +30,8 @@ type SecretInfo struct {
2730

2831
// checkSecretExists checks if a secret exists in the repository using GitHub CLI
2932
func checkSecretExists(secretName string) (bool, error) {
33+
secretsLog.Printf("Checking if secret exists: %s", secretName)
34+
3035
// Use gh CLI to list repository secrets
3136
cmd := exec.Command("gh", "secret", "list", "--json", "name")
3237
output, err := cmd.Output()
@@ -74,6 +79,7 @@ func extractSecretName(value string) string {
7479

7580
// extractSecretsFromConfig extracts all required secrets from an MCP server config
7681
func extractSecretsFromConfig(config parser.MCPServerConfig) []SecretInfo {
82+
secretsLog.Printf("Extracting secrets from MCP config: command=%s", config.Command)
7783
var secrets []SecretInfo
7884
seen := make(map[string]bool)
7985

@@ -101,6 +107,7 @@ func extractSecretsFromConfig(config parser.MCPServerConfig) []SecretInfo {
101107
}
102108
}
103109

110+
secretsLog.Printf("Extracted %d secrets from config", len(secrets))
104111
return secrets
105112
}
106113

pkg/cli/workflows.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ import (
1010
"strings"
1111

1212
"github.com/githubnext/gh-aw/pkg/console"
13+
"github.com/githubnext/gh-aw/pkg/logger"
1314
)
1415

16+
var workflowsLog = logger.New("cli:workflows")
17+
1518
// getPackagesDir returns the global packages directory path
1619
func getPackagesDir() (string, error) {
1720
// Use global directory under user's home
@@ -57,6 +60,8 @@ type GitHubWorkflow struct {
5760

5861
// fetchGitHubWorkflows fetches workflow information from GitHub
5962
func fetchGitHubWorkflows(repoOverride string, verbose bool) (map[string]*GitHubWorkflow, error) {
63+
workflowsLog.Printf("Fetching GitHub workflows: repoOverride=%s", repoOverride)
64+
6065
// Start spinner for network operation (only if not in verbose mode)
6166
spinner := console.NewSpinner("Fetching GitHub workflow status...")
6267
if !verbose {
@@ -100,6 +105,7 @@ func fetchGitHubWorkflows(repoOverride string, verbose bool) (map[string]*GitHub
100105
workflowMap[name] = &workflows[i]
101106
}
102107

108+
workflowsLog.Printf("Fetched %d GitHub workflows", len(workflowMap))
103109
return workflowMap, nil
104110
}
105111

@@ -112,6 +118,8 @@ func extractWorkflowNameFromPath(path string) string {
112118

113119
// getWorkflowStatus gets the status of a single workflow by name
114120
func getWorkflowStatus(workflowIdOrName string, repoOverride string, verbose bool) (*GitHubWorkflow, error) {
121+
workflowsLog.Printf("Getting workflow status: workflow=%s", workflowIdOrName)
122+
115123
// Extract workflow name for lookup
116124
filename := strings.TrimSuffix(filepath.Base(workflowIdOrName), ".md")
117125

pkg/workflow/docker.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ import (
88
"strings"
99

1010
"github.com/githubnext/gh-aw/pkg/console"
11+
"github.com/githubnext/gh-aw/pkg/logger"
1112
)
1213

14+
var dockerLog = logger.New("workflow:docker")
15+
1316
// collectDockerImages collects all Docker images used in MCP configurations
1417
func collectDockerImages(tools map[string]any) []string {
1518
var images []string
@@ -60,6 +63,7 @@ func collectDockerImages(tools map[string]any) []string {
6063

6164
// Sort for stable output
6265
sort.Strings(images)
66+
dockerLog.Printf("Collected %d Docker images from tools", len(images))
6367
return images
6468
}
6569

@@ -80,9 +84,12 @@ func generateDownloadDockerImagesStep(yaml *strings.Builder, dockerImages []stri
8084
// validateDockerImage checks if a Docker image exists and is accessible
8185
// Returns nil if docker is not available (with a warning printed)
8286
func validateDockerImage(image string, verbose bool) error {
87+
dockerLog.Printf("Validating Docker image: %s", image)
88+
8389
// Check if docker is available
8490
_, err := exec.LookPath("docker")
8591
if err != nil {
92+
dockerLog.Print("Docker not available, skipping image validation")
8693
// Docker not available - print warning and skip validation
8794
if verbose {
8895
fmt.Fprintln(os.Stderr, console.FormatWarningMessage(fmt.Sprintf("Docker not available - skipping validation for container image '%s'", image)))
@@ -96,10 +103,13 @@ func validateDockerImage(image string, verbose bool) error {
96103

97104
if err == nil {
98105
// Image exists locally
106+
dockerLog.Printf("Docker image found locally: %s", image)
99107
_ = output // Suppress unused variable warning
100108
return nil
101109
}
102110

111+
dockerLog.Printf("Docker image not found locally, attempting to pull: %s", image)
112+
103113
// Image doesn't exist locally, try to pull it
104114
pullCmd := exec.Command("docker", "pull", image)
105115
pullOutput, pullErr := pullCmd.CombinedOutput()

0 commit comments

Comments
 (0)