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

Improve plugin exception logging #6368

Merged
merged 12 commits into from
Apr 27, 2021

Conversation

cdmihai
Copy link
Contributor

@cdmihai cdmihai commented Apr 22, 2021

Context

Treat project cache exceptions similar to how MSBuild treats exceptions from ILogger.Initialize and ILogger.Shutdown. This avoids the "file an issue against the MSBuild team" console messages.
Treat errors logged by the project cache similar to how MSBuild treats errors logged by tasks. Which is to check whether they logged an error and if yes, shut the build down (project cache does not do "continue on error").

Changes Made

  • Adds a ProjectCacheException which gets handled similarly to LoggerException

Testing

  • Beefed up the existing exception handling tests to also assert what happens when the project cache logs errors instead of throwing exceptions.

@cdmihai cdmihai force-pushed the improvePluginExceptionLogging branch from 2856843 to a617a42 Compare April 23, 2021 18:30
@cdmihai cdmihai force-pushed the improvePluginExceptionLogging branch from 373b11f to 252e023 Compare April 24, 2021 01:30
cdmihai and others added 3 commits April 26, 2021 14:03
Co-authored-by: Rainer Sigwald <raines@microsoft.com>
There's a glob include for the entire ProjectCache directory above.
cacheItems.Count == 1,
"OnlyOneCachePluginMustBeSpecified",
string.Join("; ", cacheItems.Select(ci => ci.PluginPath)));
if (cacheItems.Count != 1)
Copy link
Member

Choose a reason for hiding this comment

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

Could this (and others) be wrapped in a new VerifyThrow 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.

Could be, but it may end up looking uglier since there's specific details like the exception type and what specific args to send to its particular constructor.

Copy link
Member

Choose a reason for hiding this comment

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

I was considering commenting similar, maybe the next iteration creates some plugin-specific ErrorUtilities method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The exception creation patterns are so particular to ProjectCacheException I'd rather just have factory methods on the type. We could pass in lambdas to ErrorUtilities but I think that would just complicate it without much benefit.

{
cacheResult = await _projectCachePlugin.GetCacheResultAsync(buildRequest, logger, _cancellationToken);
}
catch (Exception e)
Copy link
Member

Choose a reason for hiding this comment

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

Specific exception?

Copy link
Member

Choose a reason for hiding this comment

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

Looking at what this actually means, just filter out critical exceptions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It needs to be Exception because the cache can throw any exception type if it malfunctions. Filtering is done in HandlePluginException to avoid repeating it.

@cdmihai cdmihai merged commit 79bef82 into dotnet:main Apr 27, 2021
@cdmihai cdmihai deleted the improvePluginExceptionLogging branch April 27, 2021 01:27
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.

4 participants