Skip to content

Comments

print output of failed prepublish scripts #441#442

Merged
joaomoreno merged 1 commit intomicrosoft:masterfrom
iliazeus:441-stdout-of-failed-prepublish
Apr 20, 2020
Merged

print output of failed prepublish scripts #441#442
joaomoreno merged 1 commit intomicrosoft:masterfrom
iliazeus:441-stdout-of-failed-prepublish

Conversation

@iliazeus
Copy link
Contributor

This PR fixes #441

@iliazeus
Copy link
Contributor Author

https://github.com/iliazeus/vscode-vsce/commit/c21dcad6ca46bac1bd5b88f75e1d90abbc80571b wasn't good enough, because it caused stderr to be doubled

Comment on lines +934 to 936
// in case of error, stderr gets written by a top-level exception handler
if (error !== undefined) throw error;
process.stderr.write(stderr);
Copy link
Member

Choose a reason for hiding this comment

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

Maybe also print stderr.

Suggested change
// in case of error, stderr gets written by a top-level exception handler
if (error !== undefined) throw error;
process.stderr.write(stderr);
process.stderr.write(stderr);
// in case of error, stderr gets written by a top-level exception handler
if (error) {
throw 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.

Well, I don't know for sure why that happens yet, but (as I said in the comment) stderr gets printed anyway when the exception is thrown and caught somewhere on top. That is, if we print it here explicitly, it gets printed twice.

My guess is that the message of an Error that gets thrown by exec() is set to contain the stderr of a child process. Or maybe toString() of this Error gives us that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Welcome to Node.js v13.12.0.
Type ".help" for more information.
> const cp = require('child_process')
undefined
> let error
undefined
> void cp.exec('>&2 echo this gets printed to stderr && exit 1', e => error = e)
undefined
> error.toString()
'Error: Command failed: >&2 echo this gets printed to stderr && exit 1\n' +
  'this gets printed to stderr \r\n'
> error.message
'Command failed: >&2 echo this gets printed to stderr && exit 1\n' +
  'this gets printed to stderr \r\n'

@joaomoreno joaomoreno merged commit dc36c1f into microsoft:master Apr 20, 2020
@joaomoreno
Copy link
Member

Thanks! Ended up replacing exec with spawn, which gives us the ability to inherit stdio, keep order of messages and clears the double error output issue.

@joaomoreno joaomoreno added this to the April 2020 milestone Apr 20, 2020
@iliazeus iliazeus deleted the 441-stdout-of-failed-prepublish branch April 20, 2020 13:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Show vscode:prepublish script output even if it failed

2 participants