Skip to content

pkg/engine: debugPhase panics on empty patch in --debug output loop #152

@lexfrei

Description

Summary

pkg/engine/engine.go:99 indexes into patch[0] without checking that patch is non-empty. An empty patch string in the slice passed to debugPhase triggers a runtime panic instead of a clean error.

Code

// pkg/engine/engine.go:97-105
for _, patch := range patches {
    if string(patch[0]) == "@" {        // <- panic if patch == ""
        fmt.Printf(" %s=%s\n", patchOption, patch)
    } else {
        fmt.Printf("\n---")
        fmt.Printf("\n# DEBUG(phase %d): %s=\n%s", phase, patchOption, patch)
    }
}

Trigger conditions

debugPhase is invoked from applyPatchesAndRenderConfig and FullConfigProcess when opts.Debug == true (--debug flag / TALM_DEBUG). The argument patches is the rendered chart output, one entry per template file. A template that produces an empty document (e.g. an entirely conditional template where every guard evaluates false) feeds "" into the slice. Result: panic on the first iteration.

The path is gated behind --debug so the only operator-observable form is "talm crashed when I tried to debug a problem" — exactly the worst time for the tool to fail loudly.

Suggested fix

for _, patch := range patches {
    if patch == "" {
        continue   // or print a placeholder
    }
    if patch[0] == '@' {
        // ...
    }
}

Notes

Spotted by inspection while raising pkg/engine test coverage on branch test/chart-contract. Not currently triggerable from the shipped charts (every template they ship produces non-empty output), but reachable by any user-authored template that conditionally emits.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/engineIssues or PRs related to pkg/engine (rendering, MergeFileAsPatch, helm)kind/bugCategorizes issue or PR as related to a bugpriority/backlogGeneral backlog priority. Lower than priority/important-longtermtriage/acceptedIndicates an issue is ready to be actively worked on

    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