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

Report errors in subprocesses #1102

Merged
merged 5 commits into from
Jun 18, 2024
Merged

Conversation

evmiguel
Copy link
Contributor

This PR addresses #957, which raised the issue of a lack of error reporting in subprocesses.

@evmiguel evmiguel requested a review from jugglinmike May 20, 2024 20:57
Copy link
Contributor

@jugglinmike jugglinmike left a comment

Choose a reason for hiding this comment

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

Thanks for taking this up, @evmiguel!

A few of the new error messages present the current-working directory as though it were part of the command. It's good to provide the information as context, but we should probably describe it as distinct from the command which was executed.

@@ -38,6 +38,20 @@ const startServer = async serverOrClient => {
}
);

server.on('error', error => {
console.info(`Error found in startServer process: ${error}`); // eslint-disable-line no-console
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems as though the behavior of the tests will be meaningless from this moment forward, and the test runner will report that misleading error much more prominently than a stray console message. Shouldn't we interrupt test execution, instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree. I've updated the code to exit on error.


if (gitRunOutput.error) {
console.info(
`'git ${args.split(' ')} ${cwd}' failed with error ${
Copy link
Contributor

Choose a reason for hiding this comment

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

Splitting on the empty space is necessary for spawn.sync. Here, though, by coercing the resultant array back into a string, we'll end up with a misrepresentation of the command executed (e.g. git fetch origin main becomes git fetch,origin,main).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for catching this! I've updated the code to remove the split.

@evmiguel
Copy link
Contributor Author

@jugglinmike Thank you for taking a look! I've removed the directories from the console messages and addressed your feedback.

@evmiguel evmiguel requested a review from jugglinmike May 23, 2024 18:58
Copy link
Contributor

@jugglinmike jugglinmike left a comment

Choose a reason for hiding this comment

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

Introducing process.exit to communicate an error gave me pause because that appeared to stop the test runner itself. Doing so wouldn't be the end of the world because we'd still be surfacing the problem along with some useful information (thanks to the use of console.info), but we'd also be interfering with the harness's other work (e.g. running other tests, performing cleanup logic, etc.).

I found some time to experiment today, and I learned that Jest appears to overwrite the built-in process.exit so that it can gracefully handle uses like this. However, I'd wager that it was implemented to handle invocations from the application under test. Using the overridden process.exit in the test environment may technically work, but it seems a bit misleading. I've rewritten the setup logic to throw an exception which will not be caught due to its origin in an event handler. Jest also accounts for this scenario, so the result is the same (the harness reports the error and continues with the rest of its work), but this way, the code doesn't insinuate that the process will immediately exit.

@jugglinmike jugglinmike merged commit e4f4fa9 into development Jun 18, 2024
2 checks passed
@jugglinmike jugglinmike deleted the report-errors-subprocess branch June 18, 2024 02:15
howard-e added a commit that referenced this pull request Jun 24, 2024
Includes the following changes:
* #1123, addresses #791 and #792 with:
  * #1055
  * #1001
  * #1065
  * #1052 
  * #1087
  * #1098 
  * #1092
  * #1131
  * #1124
* #1128, addresses #1100
* #1102, addresses #957
* #1132
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.

2 participants