Skip to content

Commit 4d12abd

Browse files
[log] Add debug logging to workflow compiler and stringutil packages (#18564)
1 parent 8b089d1 commit 4d12abd

5 files changed

Lines changed: 29 additions & 4 deletions

File tree

‎pkg/stringutil/pat_validation.go‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@ package stringutil
33
import (
44
"errors"
55
"strings"
6+
7+
"github.com/github/gh-aw/pkg/logger"
68
)
79

10+
var patLog = logger.New("stringutil:pat_validation")
11+
812
// PATType represents the type of a GitHub Personal Access Token
913
type PATType string
1014

@@ -47,16 +51,19 @@ func (p PATType) IsValid() bool {
4751
// Returns:
4852
// - PATType: The type of the token
4953
func ClassifyPAT(token string) PATType {
54+
var patType PATType
5055
switch {
5156
case strings.HasPrefix(token, "github_pat_"):
52-
return PATTypeFineGrained
57+
patType = PATTypeFineGrained
5358
case strings.HasPrefix(token, "ghp_"):
54-
return PATTypeClassic
59+
patType = PATTypeClassic
5560
case strings.HasPrefix(token, "gho_"):
56-
return PATTypeOAuth
61+
patType = PATTypeOAuth
5762
default:
58-
return PATTypeUnknown
63+
patType = PATTypeUnknown
5964
}
65+
patLog.Printf("Classified PAT type: %s", patType)
66+
return patType
6067
}
6168

6269
// IsFineGrainedPAT returns true if the token is a fine-grained personal access token
@@ -84,6 +91,7 @@ func IsOAuthToken(token string) bool {
8491
// - error: An error with a descriptive message if the token is not valid, nil otherwise
8592
func ValidateCopilotPAT(token string) error {
8693
patType := ClassifyPAT(token)
94+
patLog.Printf("Validating Copilot PAT: type=%s", patType)
8795

8896
switch patType {
8997
case PATTypeFineGrained:

‎pkg/workflow/compiler_error_formatter.go‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,18 @@ import (
55
"fmt"
66

77
"github.com/github/gh-aw/pkg/console"
8+
"github.com/github/gh-aw/pkg/logger"
89
)
910

11+
var compilerErrorLog = logger.New("workflow:compiler_error_formatter")
12+
1013
// formatCompilerError creates a formatted compiler error message with optional error wrapping
1114
// filePath: the file path to include in the error (typically markdownPath or lockFile)
1215
// errType: the error type ("error" or "warning")
1316
// message: the error message text
1417
// cause: optional underlying error to wrap (use nil for validation errors)
1518
func formatCompilerError(filePath string, errType string, message string, cause error) error {
19+
compilerErrorLog.Printf("Formatting compiler error: file=%s, type=%s, message=%s", filePath, errType, message)
1620
formattedErr := console.FormatError(console.CompilerError{
1721
Position: console.ErrorPosition{
1822
File: filePath,
@@ -40,6 +44,7 @@ func formatCompilerError(filePath string, errType string, message string, cause
4044
// message: the error message text
4145
// cause: optional underlying error to wrap (use nil for validation errors)
4246
func formatCompilerErrorWithPosition(filePath string, line int, column int, errType string, message string, cause error) error {
47+
compilerErrorLog.Printf("Formatting compiler error: file=%s, line=%d, column=%d, type=%s, message=%s", filePath, line, column, errType, message)
4348
formattedErr := console.FormatError(console.CompilerError{
4449
Position: console.ErrorPosition{
4550
File: filePath,

‎pkg/workflow/compiler_types.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ func NewCompiler(opts ...CompilerOption) *Compiler {
176176
// Auto-detect action mode based on version in case version has been update
177177
c.actionMode = DetectActionMode(c.version)
178178

179+
logTypes.Printf("Created compiler: version=%s, actionMode=%s, skipValidation=%t, strictMode=%t", c.version, c.actionMode, c.skipValidation, c.strictMode)
180+
179181
return c
180182
}
181183

‎pkg/workflow/mcp_serena_config.go‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,24 @@ package workflow
22

33
import (
44
"strings"
5+
6+
"github.com/github/gh-aw/pkg/logger"
57
)
68

9+
var serenaConfigLog = logger.New("workflow:mcp_serena_config")
10+
711
// isSerenaInLocalMode checks if Serena tool is configured with local mode
812
func isSerenaInLocalMode(tools *ToolsConfig) bool {
913
if tools == nil || tools.Serena == nil {
1014
return false
1115
}
16+
serenaConfigLog.Printf("Serena tool mode: %s", tools.Serena.Mode)
1217
return tools.Serena.Mode == "local"
1318
}
1419

1520
// generateSerenaLocalModeSteps generates steps to start Serena MCP server locally using uvx
1621
func generateSerenaLocalModeSteps(yaml *strings.Builder) {
22+
serenaConfigLog.Print("Generating Serena local mode startup steps")
1723
// Step 1: Choose port for Serena HTTP server
1824
yaml.WriteString(" - name: Generate Serena MCP Server Config\n")
1925
yaml.WriteString(" id: serena-config\n")

‎pkg/workflow/safe_output_config.go‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import "strings"
99
func (c *Compiler) parseBaseSafeOutputConfig(configMap map[string]any, config *BaseSafeOutputConfig, defaultMax int) {
1010
// Set default max if provided
1111
if defaultMax > 0 {
12+
safeOutputsConfigLog.Printf("Setting default max: %d", defaultMax)
1213
config.Max = defaultIntStr(defaultMax)
1314
}
1415

@@ -18,11 +19,13 @@ func (c *Compiler) parseBaseSafeOutputConfig(configMap map[string]any, config *B
1819
case string:
1920
// Accept GitHub Actions expression strings
2021
if strings.HasPrefix(v, "${{") && strings.HasSuffix(v, "}}") {
22+
safeOutputsConfigLog.Printf("Parsed max as GitHub Actions expression: %s", v)
2123
config.Max = &v
2224
}
2325
default:
2426
// Convert integer/float64/etc to string via parseIntValue
2527
if maxInt, ok := parseIntValue(max); ok {
28+
safeOutputsConfigLog.Printf("Parsed max as integer: %d", maxInt)
2629
s := defaultIntStr(maxInt)
2730
config.Max = s
2831
}
@@ -32,6 +35,7 @@ func (c *Compiler) parseBaseSafeOutputConfig(configMap map[string]any, config *B
3235
// Parse github-token
3336
if githubToken, exists := configMap["github-token"]; exists {
3437
if githubTokenStr, ok := githubToken.(string); ok {
38+
safeOutputsConfigLog.Print("Parsed custom github-token from config")
3539
config.GitHubToken = githubTokenStr
3640
}
3741
}

0 commit comments

Comments
 (0)