Skip to content

[log] Add debug logging to config validation rules#958

Merged
lpcox merged 1 commit intomainfrom
log-enhance-config-rules-11c38d7507747352
Feb 15, 2026
Merged

[log] Add debug logging to config validation rules#958
lpcox merged 1 commit intomainfrom
log-enhance-config-rules-11c38d7507747352

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

Summary

This PR enhances internal/config/rules/rules.go with debug logging to help troubleshoot configuration validation issues.

Changes Made

Logger Declaration

  • Added logger import and declaration: var log = logger.New("config:rules")

Logging Enhancements (5 functions)

  1. UnsupportedType: Logs when unsupported server types are detected with context
  2. PortRange: Logs port validation attempts and failures with port values
  3. TimeoutPositive: Logs timeout validation with field names and values
  4. MountFormat: Logs mount format validation with detailed parsing context
  5. AbsolutePath: Logs path validation for both Unix and Windows paths, including success/failure outcomes

Total Impact

  • 10 meaningful logging statements added across validation functions
  • Focus on validation entry points, error conditions, and success paths
  • Provides helpful debugging context (field names, values, JSON paths)

Benefits

  • Better debugging: Visibility into which validation rules are triggered
  • Troubleshooting: Easier to diagnose why user configurations fail validation
  • Development: Helpful for understanding validation flow during development
  • No side effects: All log arguments are simple values (no function calls)

Testing Notes

The changes follow the project's logging guidelines from AGENTS.md:

  • Logger naming follows pkg:filename convention (config:rules)
  • Logging messages are meaningful and include relevant context
  • No side effects in log arguments
  • Focused on important validation decision points

Example Debug Output

When DEBUG=config:rules is enabled:

Validating port range: port=8080, jsonPath=mcpServers.github.port
Validating absolute path: field=payload_dir, value=/tmp/payloads, jsonPath=gateway.payload_dir
Valid Unix absolute path: /tmp/payloads

AI generated by Go Logger Enhancement

- 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.
@github-actions github-actions Bot added automation enhancement New feature or request labels Feb 15, 2026
@github-actions
Copy link
Copy Markdown
Contributor Author

PR Titles:
✅ Refactor: Extract marshalToResponse helper to eliminate duplicate JSON marshal pattern
✅ Refactor HTTP request initialization to eliminate duplicate code pattern
Tests:
✅ GitHub MCP (last 2 merged PRs)
✅ Serena activate_project
✅ Playwright title contains "GitHub"
✅ File write
✅ Bash cat verify
Overall: PASS

AI generated by Smoke Codex

@lpcox lpcox marked this pull request as ready for review February 15, 2026 14:14
Copilot AI review requested due to automatic review settings February 15, 2026 14:14
@lpcox lpcox merged commit cada3b3 into main Feb 15, 2026
4 checks passed
@lpcox lpcox deleted the log-enhance-config-rules-11c38d7507747352 branch February 15, 2026 14:14
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds debug logging to the config validation rules package to improve troubleshooting of configuration validation issues. It introduces a logger instance and adds 10 debug logging statements across 5 validation functions, providing visibility into validation entry points, decision paths, and failure conditions.

Changes:

  • Added logger declaration using config:rules category following the pkg:filename convention
  • Enhanced 5 validation functions (UnsupportedType, PortRange, TimeoutPositive, MountFormat, AbsolutePath) with debug logging at entry points, error paths, and success paths
  • All logging uses simple value arguments with no side effects, consistent with project guidelines
Comments suppressed due to low confidence (1)

internal/config/rules/rules.go:199

  • The MountFormat function performs multiple validation checks (empty source, absolute source path, empty dest, absolute dest path, valid mode), but only the first check failure (invalid part count) is logged. For consistency with other validation functions and better debugging, consider adding debug logging for the other validation failure paths as well.
func MountFormat(mount, jsonPath string, index int) *ValidationError {
	log.Printf("Validating mount format: mount=%s, jsonPath=%s, index=%d", mount, jsonPath, index)
	parts := strings.Split(mount, ":")
	if len(parts) < 2 || len(parts) > 3 {
		log.Printf("Mount format validation failed: invalid part count=%d", len(parts))
		return &ValidationError{
			Field:      "mounts",
			Message:    fmt.Sprintf("invalid mount format '%s' (expected 'source:dest' or 'source:dest:mode')", mount),
			JSONPath:   fmt.Sprintf("%s.mounts[%d]", jsonPath, index),
			Suggestion: "Use format 'source:dest' or 'source:dest:mode' where mode is 'ro' (read-only) or 'rw' (read-write)",
		}
	}

	source := parts[0]
	dest := parts[1]
	mode := ""
	if len(parts) == 3 {
		mode = parts[2]
	}

	// Validate source is not empty
	if source == "" {
		return &ValidationError{
			Field:      "mounts",
			Message:    fmt.Sprintf("mount source cannot be empty in '%s'", mount),
			JSONPath:   fmt.Sprintf("%s.mounts[%d]", jsonPath, index),
			Suggestion: "Provide a valid absolute source path (e.g., '/host/path')",
		}
	}

	// Validate source is an absolute path (MCP spec requirement)
	if !strings.HasPrefix(source, "/") {
		return &ValidationError{
			Field:      "mounts",
			Message:    fmt.Sprintf("mount source must be an absolute path, got '%s'", source),
			JSONPath:   fmt.Sprintf("%s.mounts[%d]", jsonPath, index),
			Suggestion: "Use an absolute path starting with '/' (e.g., '/var/data' instead of 'data')",
		}
	}

	// Validate dest is not empty
	if dest == "" {
		return &ValidationError{
			Field:      "mounts",
			Message:    fmt.Sprintf("mount destination cannot be empty in '%s'", mount),
			JSONPath:   fmt.Sprintf("%s.mounts[%d]", jsonPath, index),
			Suggestion: "Provide a valid absolute destination path (e.g., '/app/data')",
		}
	}

	// Validate dest is an absolute path (MCP spec requirement)
	if !strings.HasPrefix(dest, "/") {
		return &ValidationError{
			Field:      "mounts",
			Message:    fmt.Sprintf("mount destination must be an absolute path, got '%s'", dest),
			JSONPath:   fmt.Sprintf("%s.mounts[%d]", jsonPath, index),
			Suggestion: "Use an absolute path starting with '/' (e.g., '/app/data' instead of 'app/data')",
		}
	}

	// Validate mode if provided
	if mode != "" && mode != "ro" && mode != "rw" {
		return &ValidationError{
			Field:      "mounts",
			Message:    fmt.Sprintf("invalid mount mode '%s' (must be 'ro' or 'rw')", mode),
			JSONPath:   fmt.Sprintf("%s.mounts[%d]", jsonPath, index),
			Suggestion: "Use 'ro' for read-only or 'rw' for read-write",
		}
	}

	return nil

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

"github.com/github/gh-aw-mcpg/internal/logger"
)

var log = logger.New("config:rules")
Copy link

Copilot AI Feb 15, 2026

Choose a reason for hiding this comment

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

According to AGENTS.md guidelines, descriptive logger variable names are strongly preferred over generic 'log' (20 out of 23 logger declarations use descriptive names). Consider renaming to 'var logRules = logger.New("config:rules")' for consistency with other config validation files like 'logValidation', 'logEnv', and 'logSchema'.

Copilot uses AI. Check for mistakes.
Comment on lines 234 to +243
@@ -226,9 +240,11 @@ func AbsolutePath(value, fieldName, jsonPath string) *ValidationError {
if len(value) >= 3 &&
((value[0] >= 'A' && value[0] <= 'Z') || (value[0] >= 'a' && value[0] <= 'z')) &&
value[1] == ':' && value[2] == '\\' {
log.Printf("Valid Windows absolute path: %s", value)
Copy link

Copilot AI Feb 15, 2026

Choose a reason for hiding this comment

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

Logging success paths in validation functions can create noisy debug output, especially for frequently called functions. Consider removing the success case logging (lines 234 and 243) and only keeping entry and failure logging, which is the pattern used in other validation functions like PortRange and TimeoutPositive.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants