Skip to content

[duplicate-code] Duplicate Code Pattern: Repetitive Debug Logging in Validation #2756

@github-actions

Description

@github-actions

Part of duplicate code analysis: #2754

Summary

internal/config/validation.go and internal/config/validation_env.go contain 30+ near-identical logValidation.Printf(...) calls following the same per-function lifecycle pattern: entry log → validation steps → "passed" or "failed" log. This creates noise and inconsistency without a shared format contract.

Duplication Details

Pattern: Entry/exit debug logging repeated per validation function

  • Severity: Medium
  • Occurrences: 30+ instances across 2 files
  • Locations:
    • internal/config/validation.go (~28 instances)
    • internal/config/validation_env.go (~10 instances)

Code Sample — expandVariablesCore:

logValidation.Printf("Expanding variables: context=%s", contextDesc)
// ... logic ...
logValidation.Printf("Variable expansion completed: context=%s, undefined_count=%d",
    contextDesc, len(undefinedVars))

Code Sample — validateServerConfigWithCustomSchemas:

logValidation.Printf("Validating server config: name=%s, type=%s", name, server.Type)
// ...
logValidation.Printf("Server type empty, defaulting to stdio: name=%s", name)
// ...
logValidation.Printf("Server config validation passed: name=%s", name)

This same structure — enter, log steps, exit with "passed"/"failed" — is repeated for every validation function.

Impact Analysis

  • Maintainability: Log format inconsistencies have already crept in (some say "passed", others "completed", others "done")
  • Bug Risk: Low — logging bugs are non-critical
  • Code Bloat: ~30 one-liner log calls could be replaced with 3–5 shared helper calls

Refactoring Recommendations

  1. Create small logging helpers in internal/config/ or reuse the existing logValidation logger:
    func logValidateStart(name, typ string) {
        logValidation.Printf("Validating server config: name=%s, type=%s", name, typ)
    }
    func logValidatePassed(name string) {
        logValidation.Printf("Server config validation passed: name=%s", name)
    }
    func logValidateFailed(name, reason string) {
        logValidation.Printf("Validation failed: name=%s, reason=%s", name, reason)
    }
  2. Standardize log message vocabulary — pick one word per lifecycle event (e.g., always "passed", never "completed" or "done")
  3. Estimated effort: 1 hour

Implementation Checklist

  • Audit all logValidation.Printf calls in both files
  • Define 3–4 shared helper functions
  • Replace call sites
  • Run make test-unit to confirm no behavioral changes
  • Run make lint to verify formatting

Parent Issue

See parent analysis report: #2754
Related to #2754

Generated by Duplicate Code Detector ·

  • expires on Apr 5, 2026, 6:00 AM UTC

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions