Skip to content

Bytes and String methods inconsistent on non-zero exist status from Exec #170

@nk-87

Description

@nk-87

When calling Bytes from a pipe, it does not return an error when the Exec on the pipe returns a non-zero exit status.

// This test fails
func TestBytesFailOnCmdFail(t *testing.T) {
	_, err := script.Exec("sh -c 'exit 1'").Bytes()
	if err == nil {
		t.Fatal("expected error")
	}
}

In contrast, the String method does return an error in these situations. The difference between the two is that the final return expression in String returns *Pipe.Error() as the error return value vs nil in Bytes.

I think it would be clearer for the two methods to behave in a consistent way.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions