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
Add logging when environment variable parsing fails #1251
Conversation
47867ec
to
8e5eb6d
Compare
@csaba-sagi-sonarsource please have a look at the draft - you need to have a look at it commit by commit (skip the first one) - after #1246 gets merged I will do a rebase Tests were green, I've rewritten the commit history to be easier to read. |
its/src/test/java/com/sonar/it/scanner/msbuild/ScannerMSBuildTest.java
Outdated
Show resolved
Hide resolved
Tests/SonarScanner.MSBuild.Common.Test/AnalysisConfig/AnalysisConfigExtensionsTests.cs
Show resolved
Hide resolved
@@ -53,7 +53,7 @@ public void CreateSummaryData_ConfigIsNull_Throws() | |||
{ | |||
// Arrange |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest creating a [TestInitialize] method and create the logger there and use everywhere in the class from a private field.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left a couple of comments. Also, I would like to ask you to take a look at the code smells reported, it seems to me that at least 2/3 (except the catch one) make sense.
The URI code smell - possible refactoring rabbit hole and I don't currently understand the TFS area well enough - #1252 - if there's time in this sprint. Pragmatically, there's some tickets with higher user value than this (although this code smell can hide possible bugs). |
This code smell means removing |
4c4c60a
to
2e7aa2d
Compare
@@ -272,7 +272,7 @@ private static Path getNuGetPath(Orchestrator orch) { | |||
return nugetPath; | |||
} | |||
|
|||
private static BuildResult runMSBuildQuietly(Orchestrator orch, Path projectDir, List<EnvironmentVariable> environmentVariables, String... arguments) { | |||
public static BuildResult runMSBuildQuietly(Orchestrator orch, Path projectDir, List<EnvironmentVariable> environmentVariables, String... arguments) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: the layout of the whole file is a bit of a mess (private, public methods are all around the place and not grouped by visibility), but I don't think this IT code is the best use of our time in changing the structure (public , then private methods)
{ | ||
logger?.LogError(Resources.ERROR_FailedParsePropertiesEnvVar, ENV_VAR_KEY); | ||
logger.LogError(Resources.ERROR_FailedParsePropertiesEnvVar, ENV_VAR_KEY, ex.Message); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will fail the build, which is ok in this case (otherwise, users will be confused)
2e7aa2d
to
3eedf6d
Compare
@@ -48,7 +46,7 @@ public static bool TryCreateProvider(ILogger logger, out IAnalysisPropertyProvid | |||
provider = new EnvScannerPropertiesProvider(Environment.GetEnvironmentVariable(ENV_VAR_KEY)); | |||
return true; | |||
} | |||
catch (Exception ex) when (ex is JsonException || ex is IOException) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JsonException is in Newtonsoft 12 :|
hence failures on .NET Core 2.1
🤦
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to leave a comment here, so it will be fixed once NET 2.1 version is removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll do a separate PR to avoid postponing merging this one.
I think there's multiple things:
- filtering down the exception
- general cleanup after removing .NET 2.1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kudos, SonarCloud Quality Gate passed! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Left one comment, otherwise it is good to go.
Fix #1245