-
Notifications
You must be signed in to change notification settings - Fork 88
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
Reauthor runtime errors. #2660
Reauthor runtime errors. #2660
Conversation
|
||
//TBD resolve type mismatch | ||
_ignoredFilesCount += (uint)context.TargetsProvider.Skipped.Count; | ||
Notes.LogEmptyFileSkipped(context, artifact.Uri.GetFilePath()); |
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 that we don't track/report out on skipping 0-byte files, though we do set a non-fatal runtime condition. How interesting is it that we don't scan a 0-byte file?
I suppose we still have a problem, though, there's at least a theoretical case that someone's analysis might be intended to flag all zero-byte files. :) We could allow this lower-bound threshold to be configurable and the core engine code would probably need to be updated.
@@ -302,62 +302,69 @@ private static SarifLog GetSarifLogWithMinimalUniqueData() | |||
} | |||
|
|||
[Fact] | |||
public async Task SarifLog_Post_WithValidParameters_ShouldNotThrownAnExceptionWhenRequestIsValid() |
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.
SarifLog_Post_WithValidParameters_ShouldNotThrownAnExceptionWhenRequestIsValid
These tests were poorly factored and as a result made it difficult to locate an underlying test helper bug. It's a good object lesson for why we factor tests the way that we do, it's to lower costs in resolving regressions (in this case introduced by an update to net6.0 from netcoreapp3.1).
@@ -38,7 +38,7 @@ public void Stack_CreateFromException() | |||
{ | |||
File.Create(Path.GetInvalidFileNameChars()[0].ToString(), 0); | |||
} | |||
catch (ArgumentException exception) | |||
catch (IOException exception) |
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.
@@ -845,13 +845,13 @@ public void SarifLogger_EnhancesRunWithAdditionalAnalysisTargets() | |||
[Fact] | |||
public void SarifLogger_AcceptsOverrideOfDefaultEncoding() | |||
{ | |||
const string Utf8 = "UTF-8"; | |||
const string Utf7 = "UTF-7"; |
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.
@@ -20,6 +20,11 @@ public static StringContent AnyContent() | |||
return new StringContent(AnyContentText); | |||
} | |||
|
|||
public static HttpResponseMessage CreateOKResponse() |
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.
So, this code illustrates some of the dangers of statics. There is no such thing as a static response, once you read the stream from it, that stream is disposed.
I'm surprised we haven't gotten burned by this before. We need to revisit this test class. I took a small change along the lines of what I think we'll need, helpers that dynamically create new instances of the default data.
Though honestly, a helper that wraps a single line of code may not be worth implementing at all. :)
context.RuntimeExceptions?[0].InnerException.Should().BeNull(); | ||
context.RuntimeExceptions?[0].Should().BeNull(); | ||
|
||
context.RuntimeExceptions?[0].InnerException?.ToString().Should().BeNull(); |
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.
new HttpRequestMessage(HttpMethod.Post, postUri) | ||
{ | ||
Content = new StreamContent(CreateSarifLogStream()) | ||
}, |
Check warning
Code scanning / CodeQL
Missing Dispose call on local IDisposable Warning
/// <returns>A Result enumerator for the SARIF log.</returns> | ||
public IEnumerable<Result> Results() | ||
{ | ||
if (this.Runs?.Count > 0 == false) { yield break; } |
Check notice
Code scanning / CodeQL
Unnecessarily complex Boolean expression Note
|
||
foreach (Run run in this.Runs) | ||
{ | ||
if (run.Results?.Count > 0 == false) { continue; } |
Check notice
Code scanning / CodeQL
Unnecessarily complex Boolean expression Note
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.
The >
operator indeed returns bool
rather than bool?
. But if you used the !
operator, then you'd have to add parentheses if (!(run.Results?.Count > 0))
, which would look more complex.
I think if (run.Results?.Count ?? 0 == 0)
would be quite readable here.
|
||
public override string ToString() | ||
{ | ||
return $"{ExitReason}: {base.ToString()}"; |
Check notice
Code scanning / CodeQL
Redundant ToString() call Note
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.
Does CodeQL expect $"{ExitReason}: {base}"
? I don't think C# allows that.
httpMock.Mock( | ||
new HttpRequestMessage(HttpMethod.Post, postUri) { Content = new StreamContent(memoryStream) }, | ||
new HttpRequestMessage(HttpMethod.Post, postUri) { Content = new StreamContent(CreateSarifLogStream()) }, |
Check warning
Code scanning / CodeQL
Missing Dispose call on local IDisposable Warning
new HttpRequestMessage(HttpMethod.Post, postUri) | ||
{ | ||
Content = new StreamContent(CreateSarifLogStream()) | ||
}, |
Check warning
Code scanning / CodeQL
Missing Dispose call on local IDisposable Warning
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.
context.MaxFileSizeInKilobytes.ToString())); | ||
|
||
context.RuntimeErrors |= RuntimeConditions.OneOrMoreEmptyFilesSkipped; | ||
} |
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.
nit: missing a empty line after this function
{ | ||
if (context == null) | ||
{ | ||
throw new ArgumentNullException(nameof(context)); | ||
} | ||
|
||
// {0} file(s)s were skipped for analysis due to exceeding size limits | ||
// {0} file(s)s were skipped for analysis due to exceeding size limit | ||
// (currently configured as {1} kilobytes). The 'max-file-size-in-kb' | ||
// command-line argument can be used to increase this threshold. | ||
context.Logger.LogConfigurationNotification( |
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.
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.
@@ -197,7 +197,7 @@ public void ValidatesAllTestFiles() | |||
Path.Combine("v2", "ConverterTestData"), | |||
Path.Combine("v2", "SpecExamples"), | |||
Path.Combine("v2", "ObsoleteFormats"), | |||
Path.Combine("..", "..", "Test.UnitTests.Sarif", "netcoreapp3.1", "TestData") | |||
Path.Combine("..", "..", "Test.UnitTests.Sarif", "net6.0", "TestData") |
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.
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.
@@ -11,51 +11,98 @@ namespace Microsoft.CodeAnalysis.Sarif | |||
// code paths. These conditions are a combination of fatal | |||
// and non-fatal circumstances | |||
[Flags] | |||
public enum RuntimeConditions : uint | |||
public enum RuntimeConditions : long |
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.
@michaelcfanning we changed this to long, should we change the usage of it to use long as well,
e.g. I see the run result was int, should we also change to long?
abstract public int Run(T options);
RuntimeConditions
now of typelong
to permit more flag values. Many literal values have changed for individual members. #2660RuntimeConditions.OneOrMoreFilesSkippedDueToSize
renamed toOneOrMoreFilesSkippedDueToExceedingSizeLimits
. #2660SarifLog
level that iterates over all results in all runs in the log. #2660Notes.LogEmptyFileSkipped
helper for reporting zero-byte files skipped at scan time. #2660