Ensure error message for failed slices stay within the slice #13042
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
Background
The Werft log cutter expects each line of output to follow the specific format (docs). If no slice is specified in a log line then it will be attached to the "default" slice for that phase (which is a slice with the same id as the phase).
As we're just
console.log
'ing strings it means it's out responsibility to ensure we don't log multiline strings.The change
This PR improves our handling of slices that we explicitly fail using
werft.fail
in two important ways:werft.fail
throws an error which will eventually bubble up to our maincatch
handler. In that handler we wouldconsole.log
the error which meant that the error would always end up in the default slice (see screenshot below)With this PR any place where we use
werft.fail
we'll now ensure the error is contained to the slice, which makes it much easier to understand why a slice failed.Implementation details
I have introduced a new custom error type
SliceFailedError
which we use inwerft.fail
. In the maincatch
handler we then don't perform any additional logging.Some other notes:
[<slice>|FAIL] <reason>
Werft won't display the reason. Because of that I updated the code so the last log output for the slice is "Failed. Expand to see why" and I have left the fail reason blank.fail
ordone
a phase, only slices. I've updatedvalidate-changes.ts
so it doesn't try to do so. There are still many other places where we can make similar changes.Related Issue(s)
No issue. Friday Tid(a)y
How to test
To test this I introduced a TS error in
build.ts
and side-loaded the error to ensure that the "tsc --noEmit" slice would fail. I did this on this branch and on a branch off main to show the the difference.Before (branch off main)
After (this branch)
Release Notes
Documentation
N/A
Werft options: