Avoid using process.exit as we need to flush telemetry #8873
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
We don't always get traces from gitpod-io/gitod when the main build fails (see https://github.com/gitpod-io/ops/issues/865 for more context).
We're relying on Node's beforeExit event to ensure that we flush our traces before stopping the node process (see here). This means that we can't use process.exit in our TS scripts, as that doesn't invoke the beforeExit handlers.
We have previously gotten rid of
process.exit
invocations but had overlooked one. This PR removes it. PreviouslyreportBuildFailureInSlack
took an onErr function which it invoked once the request to slack completed (or failed). We passed in() => process.exit(1)
. I've removed the onErr argument and converted it to a promise-based API instead. We now don't do anything if the Slack requests succeeds but do log the error if it fails. The process.exitCode is moved out of the else-branch so it's always set if the build fails.Related Issue(s)
Fixes https://github.com/gitpod-io/ops/issues/865
How to test
I haven't tested this as I couldn't find an easy way to test it. Given the code change is rather trivial (though that can be deceiving) I'm happier merging and reverting if it turns out I broke the Slack notification☺️
Release Notes
Documentation
N/A