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

Add logging when environment variable parsing fails #1251

Merged
merged 10 commits into from Jun 15, 2022

Conversation

andrei-epure-sonarsource
Copy link
Contributor

Fix #1245

@andrei-epure-sonarsource
Copy link
Contributor Author

@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.

@@ -53,7 +53,7 @@ public void CreateSummaryData_ConfigIsNull_Throws()
{
// Arrange
Copy link
Contributor

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.

Copy link
Contributor

@csaba-sagi-sonarsource csaba-sagi-sonarsource left a 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.

@andrei-epure-sonarsource
Copy link
Contributor Author

andrei-epure-sonarsource commented Jun 9, 2022

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).

@andrei-epure-sonarsource
Copy link
Contributor Author

This code smell means removing ConfigSettingsExtensions and moving all methods inside AnalysisConfig - which is valid, but I need first to understand why the methods have been separated in the first place and whether the serialization is affected in any way by doing this move.

@@ -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) {
Copy link
Contributor Author

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);
Copy link
Contributor Author

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)

@andrei-epure-sonarsource andrei-epure-sonarsource marked this pull request as ready for review June 10, 2022 10:16
@@ -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)
Copy link
Contributor Author

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

🤦

Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sonarcloud
Copy link

sonarcloud bot commented Jun 14, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 3 Code Smells

97.9% 97.9% Coverage
0.0% 0.0% Duplication

Copy link
Contributor

@csaba-sagi-sonarsource csaba-sagi-sonarsource left a 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.

@andrei-epure-sonarsource andrei-epure-sonarsource merged commit 2c3a8fe into master Jun 15, 2022
@andrei-epure-sonarsource andrei-epure-sonarsource deleted the andrei/1245 branch June 15, 2022 10:21
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.

Add logging to Azure Devops settings parser
2 participants