Log before unregistering Fixes #9455 #9571
Merged
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.
Fixes #9455
Context
If we crash very early—like in the midst of setting up the ProjectLoggingContext—we have all the machinery set up to log information like that the build started, but then we unregister the relevant handlers before we actually log that we'd failed.
Changes Made
Do not unregister handlers until shutdown
Testing
I tested with the repro from #9455, and it now looks like this:
(with a full stack trace).
Notice that it finds the real exception—just an ordinary System.Exception with no message in this case.
Notes
I went directly against the advice of a comment to make this change. I tried to see what motivated that comment, but it came with the initial commit along with all the code next to it. Regardless, it does not make me feel good to do so. I don't understand why the comment should be true, but please do read it and let me know if this is a horrible idea.
I also intentionally reused MSB4017 because this feels like the same exception, and I didn't want to confuse people. I just added some extra formatting around it. Like with going against the comment, I can find a new number if reviewers don't like that idea.