Skip to content

[duplicate-code] Duplicate Code Pattern: NoopGuard Uses Wrong Logger (Dead Code + Misattributed Logs) #2362

@github-actions

Description

@github-actions

Part of duplicate code analysis: #2361

Summary

internal/guard/noop.go defines its own logNoop logger variable but all three of its methods call log.Printf() instead — resolving to the package-level log variable defined in internal/guard/context.go (namespace "guard:context"). This leaves logNoop as dead code and causes all NoopGuard log messages to appear under the wrong namespace.

Duplication Details

Pattern: Wrong Logger Variable Used (Copy-Paste Bug)

  • Severity: High

  • Occurrences: 4 misattributed log calls in noop.go

  • Locations:

    • internal/guard/noop.go line 10 — defines var logNoop = logger.New("guard:noop") (never used)
    • internal/guard/noop.go line 29 — calls log.Printf(...) (should be logNoop.Printf)
    • internal/guard/noop.go line 42 — calls log.Printf(...) (should be logNoop.Printf)
    • internal/guard/noop.go line 52 — calls log.Printf(...) (should be logNoop.Printf)
    • internal/guard/noop.go line 61 — calls log.Printf(...) (should be logNoop.Printf)
    • internal/guard/context.go line 29 — defines package-level var log = logger.New("guard:context")
  • Code Sample:

    // noop.go — defines own logger but never uses it
    var logNoop = logger.New("guard:noop")  // line 10: DEFINED but unused
    
    func (g *NoopGuard) LabelAgent(...) (*LabelAgentResult, error) {
        log.Printf("Initializing agent labels with noop guard")  // line 29: uses context.go's `log`
        ...
    }
    
    func (g *NoopGuard) LabelResource(...) (...) {
        log.Printf("Labeling resource: ...")  // line 42: uses context.go's `log`
        ...
        log.Printf("Resource labeled with no restrictions: ...")  // line 52: uses context.go's `log`
        ...
    }
    
    func (g *NoopGuard) LabelResponse(...) (...) {
        log.Printf("Labeling response: ...")  // line 61: uses context.go's `log`
        ...
    }

Impact Analysis

  • Maintainability: logNoop variable is dead code; developers cannot filter noop guard logs with DEBUG=guard:noop
  • Bug Risk: Log messages from NoopGuard are silently swallowed under guard:context namespace, making debugging misleading
  • Code Bloat: Unused logNoop variable adds confusion

Refactoring Recommendations

  1. Replace all log.Printf calls with logNoop.Printf in noop.go:
    • Line 29: log.Printf(...)logNoop.Printf(...)
    • Line 42: log.Printf(...)logNoop.Printf(...)
    • Line 52: log.Printf(...)logNoop.Printf(...)
    • Line 61: log.Printf(...)logNoop.Printf(...)
    • Estimated effort: 5 minutes
    • Benefits: Correct log attribution, logNoop no longer dead code, DEBUG=guard:noop filtering works

Implementation Checklist

  • Replace log.Printf with logNoop.Printf on lines 29, 42, 52, 61 of noop.go
  • Verify logNoop is now used (no dead code)
  • Confirm DEBUG=guard:noop correctly shows NoopGuard logs
  • Run make test to verify no regressions

Parent Issue

See parent analysis report: #2361
Related to #2361

Generated by Duplicate Code Detector ·

Warning

⚠️ Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • proxy.golang.org

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "proxy.golang.org"

See Network Configuration for more information.

  • expires on Mar 30, 2026, 3:05 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