Skip to content

Commit e052189

Browse files
Add debug logging to config validation rules
- Add logger import and declaration to internal/config/rules/rules.go - Add logging to 5 key validation functions for better debugging: * UnsupportedType: Log unsupported type detection * PortRange: Log port validation with pass/fail outcomes * TimeoutPositive: Log timeout validation with values * MountFormat: Log mount format validation with context * AbsolutePath: Log path validation for Unix/Windows paths Helps troubleshoot configuration validation issues by providing visibility into which validation rules are triggered and why they fail or succeed.
1 parent 039a262 commit e052189

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

internal/config/rules/rules.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@ package rules
33
import (
44
"fmt"
55
"strings"
6+
7+
"github.com/github/gh-aw-mcpg/internal/logger"
68
)
79

10+
var log = logger.New("config:rules")
11+
812
// Documentation URL constants
913
const (
1014
ConfigSpecURL = "https://github.com/github/gh-aw/blob/main/docs/src/content/docs/reference/mcp-gateway.md"
@@ -37,6 +41,7 @@ func (e *ValidationError) Error() string {
3741

3842
// UnsupportedType creates a ValidationError for unsupported type values
3943
func UnsupportedType(fieldName, actualType, jsonPath, suggestion string) *ValidationError {
44+
log.Printf("Validation error: unsupported type at %s.%s, type=%s", jsonPath, fieldName, actualType)
4045
return &ValidationError{
4146
Field: fieldName,
4247
Message: fmt.Sprintf("unsupported server type '%s'", actualType),
@@ -86,7 +91,9 @@ func AppendConfigDocsFooter(sb *strings.Builder) {
8691
// PortRange validates that a port is in the valid range (1-65535)
8792
// Returns nil if valid, *ValidationError if invalid
8893
func PortRange(port int, jsonPath string) *ValidationError {
94+
log.Printf("Validating port range: port=%d, jsonPath=%s", port, jsonPath)
8995
if port < 1 || port > 65535 {
96+
log.Printf("Port validation failed: port=%d out of range", port)
9097
return &ValidationError{
9198
Field: "port",
9299
Message: fmt.Sprintf("port must be between 1 and 65535, got %d", port),
@@ -100,7 +107,9 @@ func PortRange(port int, jsonPath string) *ValidationError {
100107
// TimeoutPositive validates that a timeout value is at least 1
101108
// Returns nil if valid, *ValidationError if invalid
102109
func TimeoutPositive(timeout int, fieldName, jsonPath string) *ValidationError {
110+
log.Printf("Validating timeout: field=%s, value=%d, jsonPath=%s", fieldName, timeout, jsonPath)
103111
if timeout < 1 {
112+
log.Printf("Timeout validation failed: %s=%d is not positive", fieldName, timeout)
104113
return &ValidationError{
105114
Field: fieldName,
106115
Message: fmt.Sprintf("%s must be at least 1, got %d", fieldName, timeout),
@@ -118,8 +127,10 @@ func TimeoutPositive(timeout int, fieldName, jsonPath string) *ValidationError {
118127
// - Container path MUST be an absolute path
119128
// - Mode (if provided) MUST be either "ro" (read-only) or "rw" (read-write)
120129
func MountFormat(mount, jsonPath string, index int) *ValidationError {
130+
log.Printf("Validating mount format: mount=%s, jsonPath=%s, index=%d", mount, jsonPath, index)
121131
parts := strings.Split(mount, ":")
122132
if len(parts) < 2 || len(parts) > 3 {
133+
log.Printf("Mount format validation failed: invalid part count=%d", len(parts))
123134
return &ValidationError{
124135
Field: "mounts",
125136
Message: fmt.Sprintf("invalid mount format '%s' (expected 'source:dest' or 'source:dest:mode')", mount),
@@ -207,7 +218,9 @@ func NonEmptyString(value, fieldName, jsonPath string) *ValidationError {
207218
// Pattern: ^(/|[A-Za-z]:\\)
208219
// Returns nil if valid, *ValidationError if invalid
209220
func AbsolutePath(value, fieldName, jsonPath string) *ValidationError {
221+
log.Printf("Validating absolute path: field=%s, value=%s, jsonPath=%s", fieldName, value, jsonPath)
210222
if value == "" {
223+
log.Printf("Absolute path validation failed: %s is empty", fieldName)
211224
return &ValidationError{
212225
Field: fieldName,
213226
Message: fmt.Sprintf("%s cannot be empty", fieldName),
@@ -218,6 +231,7 @@ func AbsolutePath(value, fieldName, jsonPath string) *ValidationError {
218231

219232
// Check for Unix absolute path (starts with /)
220233
if strings.HasPrefix(value, "/") {
234+
log.Printf("Valid Unix absolute path: %s", value)
221235
return nil
222236
}
223237

@@ -226,9 +240,11 @@ func AbsolutePath(value, fieldName, jsonPath string) *ValidationError {
226240
if len(value) >= 3 &&
227241
((value[0] >= 'A' && value[0] <= 'Z') || (value[0] >= 'a' && value[0] <= 'z')) &&
228242
value[1] == ':' && value[2] == '\\' {
243+
log.Printf("Valid Windows absolute path: %s", value)
229244
return nil
230245
}
231246

247+
log.Printf("Absolute path validation failed: %s=%s is not absolute", fieldName, value)
232248
return &ValidationError{
233249
Field: fieldName,
234250
Message: fmt.Sprintf("%s must be an absolute path, got '%s'", fieldName, value),

0 commit comments

Comments
 (0)