mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
C#: Add alert suppression comments. Rename e to ex in catch clauses for consistency.
This commit is contained in:
@@ -39,7 +39,7 @@ namespace Semmle.Autobuild
|
||||
{
|
||||
projFile = builder.Actions.LoadXml(FullPath);
|
||||
}
|
||||
catch (Exception e) when (e is XmlException || e is FileNotFoundException)
|
||||
catch (Exception ex) when (ex is XmlException || ex is FileNotFoundException)
|
||||
{
|
||||
builder.Log(Severity.Info, $"Unable to read project file {path}.");
|
||||
return;
|
||||
|
||||
@@ -63,7 +63,7 @@ namespace Semmle.Autobuild
|
||||
{
|
||||
solution = SolutionFile.Parse(FullPath);
|
||||
}
|
||||
catch (Exception e) when (e is InvalidProjectFileException || e is FileNotFoundException)
|
||||
catch (Exception ex) when (ex is InvalidProjectFileException || ex is FileNotFoundException)
|
||||
{
|
||||
// We allow specifying projects as solutions in lgtm.yml, so model
|
||||
// that scenario as a solution with just that one project
|
||||
|
||||
@@ -143,7 +143,7 @@ namespace Semmle.Extraction.CIL.Entities
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
catch (Exception ex) // lgtm[cs/catch-of-all-exceptions]
|
||||
{
|
||||
logger.Log(Severity.Error, string.Format("Exception extracting {0}: {1}", assemblyPath, ex));
|
||||
}
|
||||
|
||||
@@ -283,7 +283,7 @@ namespace Semmle.BuildAnalyser
|
||||
}
|
||||
++succeededProjects;
|
||||
}
|
||||
catch (Exception ex)
|
||||
catch (Exception ex) // lgtm[cs/catch-of-all-exceptions]
|
||||
{
|
||||
++failedProjects;
|
||||
progressMonitor.FailedProjectFile(proj.FullName, ex.Message);
|
||||
|
||||
@@ -183,10 +183,10 @@ namespace Semmle.BuildAnalyser
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
when (e is System.ComponentModel.Win32Exception || e is FileNotFoundException)
|
||||
catch (Exception ex)
|
||||
when (ex is System.ComponentModel.Win32Exception || ex is FileNotFoundException)
|
||||
{
|
||||
pm.FailedNugetCommand(pi.FileName, pi.Arguments, e.Message);
|
||||
pm.FailedNugetCommand(pi.FileName, pi.Arguments, ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -97,7 +97,7 @@ namespace Semmle.Extraction.CSharp
|
||||
extractor.SetAssemblyFile(assemblyIdentity, refPath);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
catch (Exception ex) // lgtm[cs/catch-of-all-exceptions]
|
||||
{
|
||||
extractor.Message(new Message
|
||||
{
|
||||
@@ -272,7 +272,7 @@ namespace Semmle.Extraction.CSharp
|
||||
ReportProgress(assemblyPath, trapWriter.TrapFile, stopwatch.Elapsed, skipExtraction ? AnalysisAction.UpToDate : AnalysisAction.Extracted);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
catch (Exception ex) // lgtm[cs/catch-of-all-exceptions]
|
||||
{
|
||||
Logger.Log(Severity.Error, " Unhandled exception analyzing {0}: {1}", r.FilePath, ex);
|
||||
}
|
||||
@@ -354,7 +354,7 @@ namespace Semmle.Extraction.CSharp
|
||||
|
||||
ReportProgress(sourcePath, trapPath, stopwatch.Elapsed, excluded ? AnalysisAction.Excluded : upToDate ? AnalysisAction.UpToDate : AnalysisAction.Extracted);
|
||||
}
|
||||
catch (Exception ex)
|
||||
catch (Exception ex) // lgtm[cs/catch-of-all-exceptions]
|
||||
{
|
||||
extractor.Message(new Message { exception = ex, message = string.Format("Unhandled exception processing {0}: {1}", tree.FilePath, ex), severity = Severity.Error });
|
||||
}
|
||||
|
||||
@@ -165,9 +165,9 @@ namespace Semmle.Extraction.CSharp
|
||||
|
||||
return analyser.TotalErrors == 0 ? ExitCode.Ok : ExitCode.Errors;
|
||||
}
|
||||
catch (Exception e)
|
||||
catch (Exception ex) // lgtm[cs/catch-of-all-exceptions]
|
||||
{
|
||||
logger.Log(Severity.Error, " Unhandled exception: {0}", e);
|
||||
logger.Log(Severity.Error, " Unhandled exception: {0}", ex);
|
||||
return ExitCode.Errors;
|
||||
}
|
||||
}
|
||||
@@ -354,9 +354,9 @@ namespace Semmle.Extraction.CSharp
|
||||
|
||||
pm.MissingSummary(analyser.MissingTypes.Count(), analyser.MissingNamespaces.Count());
|
||||
}
|
||||
catch (Exception e)
|
||||
catch (Exception ex) // lgtm[cs/catch-of-all-exceptions]
|
||||
{
|
||||
analyser.Logger.Log(Severity.Error, " Unhandled exception: {0}", e);
|
||||
analyser.Logger.Log(Severity.Error, " Unhandled exception: {0}", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,9 +54,9 @@ namespace Semmle.Extraction.CSharp.Populators
|
||||
{
|
||||
node.Accept(new Ast(cx, parent, child));
|
||||
}
|
||||
catch (System.Exception e)
|
||||
catch (System.Exception ex) // lgtm[cs/catch-of-all-exceptions]
|
||||
{
|
||||
cx.ModelError(node, "Exception processing syntax node of type {0}: {1}", node.Kind(), e);
|
||||
cx.ModelError(node, "Exception processing syntax node of type {0}: {1}", node.Kind(), ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,9 +55,9 @@ namespace Semmle.Extraction.CSharp.Populators
|
||||
{
|
||||
return symbol.Accept(new Symbols(cx));
|
||||
}
|
||||
catch (Exception e)
|
||||
catch (Exception ex) // lgtm[cs/catch-of-all-exceptions]
|
||||
{
|
||||
cx.ModelError(symbol, "Exception processing symbol '{2}' of type '{0}': {1}", symbol.Kind, e, symbol);
|
||||
cx.ModelError(symbol, "Exception processing symbol '{2}' of type '{0}': {1}", symbol.Kind, ex, symbol);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -216,13 +216,13 @@ namespace Semmle.Extraction
|
||||
{
|
||||
populateQueue.Dequeue()();
|
||||
}
|
||||
catch (InternalError e)
|
||||
catch (InternalError ex)
|
||||
{
|
||||
Extractor.Message(e.ExtractionMessage);
|
||||
Extractor.Message(ex.ExtractionMessage);
|
||||
}
|
||||
catch (Exception e)
|
||||
catch (Exception ex) // lgtm[cs/catch-of-all-exceptions]
|
||||
{
|
||||
Extractor.Message(new Message { severity = Severity.Error, exception = e, message = "Uncaught exception" });
|
||||
Extractor.Message(new Message { severity = Severity.Error, exception = ex, message = "Uncaught exception" });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -504,7 +504,7 @@ namespace Semmle.Extraction
|
||||
{
|
||||
a();
|
||||
}
|
||||
catch (Exception ex)
|
||||
catch (Exception ex) // lgtm[cs/catch-of-all-exceptions]
|
||||
{
|
||||
var internalError = ex as InternalError;
|
||||
var message = internalError != null
|
||||
|
||||
@@ -190,7 +190,7 @@ namespace Semmle.Extraction
|
||||
FileUtils.TryDelete(tmpFile);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
catch (Exception ex) // lgtm[cs/catch-of-all-exceptions]
|
||||
{
|
||||
Logger.Log(Severity.Error, "Failed to move the trap file from {0} to {1} because {2}", tmpFile, TrapFile, ex);
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ namespace Semmle.Util
|
||||
/// <returns>The canonical path.</returns>
|
||||
public override string GetCanonicalPath(string path, IPathCache cache)
|
||||
{
|
||||
using (var hFile = Win32.CreateFile(
|
||||
using (var hFile = Win32.CreateFile( // lgtm[cs/call-to-unmanaged-code]
|
||||
path,
|
||||
0,
|
||||
Win32.FILE_SHARE_READ | Win32.FILE_SHARE_WRITE,
|
||||
@@ -88,13 +88,13 @@ namespace Semmle.Util
|
||||
else
|
||||
{
|
||||
StringBuilder outPath = new StringBuilder(Win32.MAX_PATH);
|
||||
int length = Win32.GetFinalPathNameByHandle(hFile, outPath, outPath.Capacity, 0);
|
||||
int length = Win32.GetFinalPathNameByHandle(hFile, outPath, outPath.Capacity, 0); // lgtm[cs/call-to-unmanaged-code]
|
||||
if (length >= outPath.Capacity)
|
||||
{
|
||||
// Path length exceeded MAX_PATH.
|
||||
// Possible if target has a long path.
|
||||
outPath = new StringBuilder(length + 1);
|
||||
length = Win32.GetFinalPathNameByHandle(hFile, outPath, outPath.Capacity, 0);
|
||||
length = Win32.GetFinalPathNameByHandle(hFile, outPath, outPath.Capacity, 0); // lgtm[cs/call-to-unmanaged-code]
|
||||
}
|
||||
|
||||
const int PREAMBLE = 4; // outPath always starts \\?\
|
||||
|
||||
@@ -74,9 +74,9 @@ namespace Semmle.Util.Logging
|
||||
FileShare.ReadWrite, 8192));
|
||||
writer.AutoFlush = true;
|
||||
}
|
||||
catch (Exception e)
|
||||
catch (Exception ex) // lgtm[cs/catch-of-all-exceptions]
|
||||
{
|
||||
Console.Error.WriteLine("SEMMLE: Couldn't initialise C# extractor output: " + e.Message + "\n" + e.StackTrace);
|
||||
Console.Error.WriteLine("SEMMLE: Couldn't initialise C# extractor output: " + ex.Message + "\n" + ex.StackTrace);
|
||||
Console.Error.Flush();
|
||||
throw;
|
||||
}
|
||||
|
||||
@@ -11,14 +11,14 @@ namespace Semmle.Util
|
||||
public class Win32
|
||||
{
|
||||
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
|
||||
public static extern int GetFinalPathNameByHandle(
|
||||
public static extern int GetFinalPathNameByHandle( // lgtm[cs/unmanaged-code]
|
||||
SafeHandle handle,
|
||||
[In, Out] StringBuilder path,
|
||||
int bufLen,
|
||||
int flags);
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
|
||||
public static extern SafeFileHandle CreateFile(
|
||||
public static extern SafeFileHandle CreateFile( // lgtm[cs/unmanaged-code]
|
||||
string filename,
|
||||
uint desiredAccess,
|
||||
uint shareMode,
|
||||
|
||||
Reference in New Issue
Block a user