Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clarify getStderr behaviour when STDERR is not available #112

Open
azjezz opened this issue May 10, 2024 · 0 comments
Open

clarify getStderr behaviour when STDERR is not available #112

azjezz opened this issue May 10, 2024 · 0 comments

Comments

@azjezz
Copy link
Contributor

azjezz commented May 10, 2024

currently, ByteStream\getStderr has a weird behaviour in my opnion when the standard error output is not available. which is that ByteStream\getStderr() returns a stream, but, it is not the expected STDERR stream, instead, its a php://memory stream that has been closed.

I would expect either:

  1. return null indicating that the stream is not available
  2. throw an exception informing me that the stream is not available

It would be good if this behaviour could be clarified maybe via documentation. and maybe introducing a new function that has a ( IMO ) saner behaviour?


For context, i was trying to replicate this:

    /**
     * Returns the default terminal output.
     *
     * @internal
     */
    public static function getOutput(): OutputInterface
    {
        $standardOutputHandle = IO\output_handle();
        $standardErrorOutputHandle = IO\error_handle();
        if (null === $standardErrorOutputHandle) {
            return new HandleOutput($standardOutputHandle);
        }

        return new HandleConsoleOutput($standardOutputHandle, $standardErrorOutputHandle);
    }

which is possible to replicate with the current behaviour:

    /**
     * Returns the default terminal output.
     *
     * @internal
     */
    public static function getOutput(): OutputInterface
    {
        $standardOutputStream = ByteStream\getStdout();
        $standardErrorOutputStream = ByteStream\getStderr();
        if ($standardErrorOutputStream->isClosed()) {
            return new ByteStreamOutput($standardOutputStream);
        }

        return new ByteStreamConsoleOutput($standardOutputStream, $standardErrorOutputStream);
    }

however, this implementation took me a bit of time to figure out as Amp does not mention anything about returning a closed stream from getStderr.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants
@azjezz and others