Skip to content

Exit method #140

@bitfield

Description

@bitfield

Several people have noted that the behaviour of Stdout is a bit puzzling when there's an error in the pipe, especially for beginners: it just prints nothing! Unless the program checks the return value of Stdout, there's nothing to indicate that an error happened.

To make it easier to write one-liners, I propose an Exit method that behaves like Stdout, but also prints any pipe error to stderr and calls os.Exit with the appropriate exit status. For example:

script.Get(URL).Exit()

Depending on the HTTP response, we might see as a result:

HTTP/1.1 404 Not Found

with

echo $?
1

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