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

fix(src/build): output child process stderr to console.error #1998

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

jyyi1
Copy link
Contributor

@jyyi1 jyyi1 commented Apr 24, 2024

This PR redirects stderr of a child process to console.error. This allows us to view the build steps of client/src/tun2socks/build, because go run task will output to stderr.

Additionally, unnecessary line breaks have been removed to improve the readability of the output.

Before
image

After
image

@jyyi1 jyyi1 requested a review from a team as a code owner April 24, 2024 04:24
@fortuna fortuna removed request for a team and fortuna April 24, 2024 15:23
src/build/spawn_stream.mjs Outdated Show resolved Hide resolved
return new Transform({
// transform will be called whenever the upstream source pushes data to us
transform(chunk, encoding, done) {
const lines = chunk.toString().split('\n');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can pass the encoding to toString?

Copy link
Contributor Author

@jyyi1 jyyi1 Apr 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, it seems encoding will always be "buffer", and toString() doesn't like it. And the official doc tells us to ignore "buffer".

transform._transform(chunk, encoding, callback)
chunk <Buffer> | <string> | <any> The Buffer to be transformed, converted from the string passed to stream.write().
encoding <string> If the chunk is a string, then this is the encoding type. If chunk is a buffer, then this is the special value 'buffer'. Ignore it in that case.
callback <Function> A callback function (optionally with an error argument and data) to be called after the supplied chunk has been processed.

But I added a comment there so people will know why we are ignoring the encoding here.


childProcess.stderr.on('data', error => forEachMessageLine(error, line => stderr.push(line)));
const stdErrPipe = newChildProcessOutputPipeTransform(line => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One of the problems I was trying to solve here was to draw a visual distinction between what came from stderr and what didn't. This still will be the case (we're logging the entire contents of stderr below) but maybe we can prefix each line with [STDERR] or something like that as we log it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is stderr doesn't always mean error. For example, in the case of the taskfile, it outputs normal content to stderr (see the image I attached above). If we prepend [STDERR] to each line, it might actually cause confusion.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not so sure, esp. if we also prepend the stdout lines as well. We're clarifying which stream a given log is coming from, in that case - not that it's an error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, so I think the question is why do we want to distinguish from these two streams? If you run a command in the terminal, it won't tell any difference. The command will use colors or log types like ERROR: xxx to tell the user whether there are any errors.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you run a command in the terminal, it won't tell any difference

I feel like that's a flaw, and if you're debugging something, ideally the issue would be coming from stderr, so it's good UX to focus on that content.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's take an example of this output:
image

The first three lines are from stdout, and all the following are from stderr. Do you prefer we output something like the following?

[stdout] Running [node '--trace-uncaught' ...
[stdout] Running [go 'run' ...
[stdout] task: [/home/runner/work/...]
[stderr] task: "client:tun2socks:linux" started
[stderr] task: "client:tun2socks:electron" started
 ...
[stderr]
[stderr] task "client:tun2socks:electron" finished
[stderr] task "client:tun2socks:linux" finished

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do, actually. I know that in your example nothing sent from stderr is actually an error, but shouldn't it be stdout? Is there a reason the lifecycle logs are stderr?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to differentiate info output from the Task app from the actual task output. That's why the difference.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, as @jyyi1 pointed out, stderr output doesn't have to mean error. Logging uses that in general.

@daniellacosse
Copy link
Contributor

daniellacosse commented May 3, 2024 via email

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

Successfully merging this pull request may close these issues.

None yet

3 participants