Skip to content

Detect ineffectual append(cmd.Env, ...) #1689

@FiloSottile

Description

@FiloSottile

os/exec.Command returns a Cmd with only Path and Args filled out.

That means that doing

cmd := exec.Command("foo")
cmd.Env = append(cmd.Env, "FOO=bar")

is always equivalent to

cmd := exec.Command("foo")
cmd.Env = []string{"FOO=bar"}

but almost certainly intended to be

cmd := exec.Command("foo")
cmd.Env = append(cmd.Environ(), "FOO=bar")

instead.

I introduced this bug at least a couple times in the standard library tests.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions