Skip to content

Sync Main (autogenerated) #195

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

Closed
wants to merge 1,123 commits into from
Closed

Sync Main (autogenerated) #195

wants to merge 1,123 commits into from

Conversation

dilanbhalla
Copy link
Collaborator

This PR syncs the latest changes from codeql-cli/latest into main.

Jami Cogswell and others added 30 commits March 24, 2025 10:23
… query with a PrintAst name from QlRefInlineExpectations.
This allows the string of package feeds to be constructed once and used repeatedly in the parallel restore loop as well.
…us-id

Docs: add guidance for `previous-id` metadata
…stinlineexpect

QL4QL: Exclude PrintAst like tests from being reported as having missing InlineExpectations.
In particular for `postForm` `putForm` `patchForm` `getUri`.
Paolo Tranquilli and others added 26 commits March 31, 2025 13:07
…rof-rewriting

Java buildless: add buildless-maven variant with a wildcard mirrorOf spec
…-swift

Misc: Add another path prefix to accept-expected-changes-from-ci.py
Rust: rename several entities to their more natural names
…e-bom-downloads

Java: add test exercising Gradle download pruning
Release preparation for version 2.21.0
Compatible with the latest released version of the CodeQL CLI
Comment on lines +821 to +845
if (nugetConfigs.Count > 0)
{
// We don't have to get the feeds from each of the folders from below, it would be enought to check the folders that recursively contain the others.
allFeeds = nugetConfigs
.Select(config =>
{
logger.LogWarning($"Failed to get directory of '{config}': {exc}");
}
return null;
})
.Where(folder => folder != null)
.SelectMany(folder => GetFeeds(() => dotnet.GetNugetFeedsFromFolder(folder!)))
.ToHashSet();
try
{
return new FileInfo(config).Directory?.FullName;
}
catch (Exception exc)
{
logger.LogWarning($"Failed to get directory of '{config}': {exc}");
}
return null;
})
.Where(folder => folder != null)
.SelectMany(folder => GetFeeds(() => dotnet.GetNugetFeedsFromFolder(folder!)))
.ToHashSet();
}
else
{
// If we haven't found any `nuget.config` files, then obtain a list of feeds from the root source directory.
allFeeds = GetFeeds(() => dotnet.GetNugetFeedsFromFolder(this.fileProvider.SourceDir.FullName)).ToHashSet();
}

Check notice

Code scanning / CodeQL

Missed ternary opportunity Note

Both branches of this 'if' statement write to the same variable - consider using '?' to express intent better.

Copilot Autofix

AI 4 months ago

To fix the problem, we will replace the if statement with a ternary operator to assign the value to the allFeeds variable. We will also move the logging statements outside the ternary operator to ensure they are executed appropriately based on the condition.

  • Replace the if statement on lines 821-845 with a ternary operator.
  • Move the logging statements to be executed based on the condition separately.
Suggested changeset 1
csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/NugetPackageRestorer.cs

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/NugetPackageRestorer.cs b/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/NugetPackageRestorer.cs
--- a/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/NugetPackageRestorer.cs
+++ b/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/NugetPackageRestorer.cs
@@ -818,8 +818,4 @@
             // todo: this could be improved.
-            HashSet<string>? allFeeds = null;
-
-            if (nugetConfigs.Count > 0)
-            {
-                // We don't have to get the feeds from each of the folders from below, it would be enought to check the folders that recursively contain the others.
-                allFeeds = nugetConfigs
+            HashSet<string>? allFeeds = nugetConfigs.Count > 0
+                ? nugetConfigs
                     .Select(config =>
@@ -838,3 +834,8 @@
                     .SelectMany(folder => GetFeeds(() => dotnet.GetNugetFeedsFromFolder(folder!)))
-                    .ToHashSet();
+                    .ToHashSet()
+                : GetFeeds(() => dotnet.GetNugetFeedsFromFolder(this.fileProvider.SourceDir.FullName)).ToHashSet();
+
+            if (nugetConfigs.Count > 0)
+            {
+                logger.LogInfo($"Found {allFeeds.Count} Nuget feeds (with inherited ones) in nuget.config files: {string.Join(", ", allFeeds.OrderBy(f => f))}");
             }
@@ -842,8 +843,5 @@
             {
-                // If we haven't found any `nuget.config` files, then obtain a list of feeds from the root source directory.
-                allFeeds = GetFeeds(() => dotnet.GetNugetFeedsFromFolder(this.fileProvider.SourceDir.FullName)).ToHashSet();
+                logger.LogDebug("No Nuget feeds found in nuget.config files.");
             }
 
-            logger.LogInfo($"Found {allFeeds.Count} Nuget feeds (with inherited ones) in nuget.config files: {string.Join(", ", allFeeds.OrderBy(f => f))}");
-
             return (explicitFeeds, allFeeds);
EOF
@@ -818,8 +818,4 @@
// todo: this could be improved.
HashSet<string>? allFeeds = null;

if (nugetConfigs.Count > 0)
{
// We don't have to get the feeds from each of the folders from below, it would be enought to check the folders that recursively contain the others.
allFeeds = nugetConfigs
HashSet<string>? allFeeds = nugetConfigs.Count > 0
? nugetConfigs
.Select(config =>
@@ -838,3 +834,8 @@
.SelectMany(folder => GetFeeds(() => dotnet.GetNugetFeedsFromFolder(folder!)))
.ToHashSet();
.ToHashSet()
: GetFeeds(() => dotnet.GetNugetFeedsFromFolder(this.fileProvider.SourceDir.FullName)).ToHashSet();

if (nugetConfigs.Count > 0)
{
logger.LogInfo($"Found {allFeeds.Count} Nuget feeds (with inherited ones) in nuget.config files: {string.Join(", ", allFeeds.OrderBy(f => f))}");
}
@@ -842,8 +843,5 @@
{
// If we haven't found any `nuget.config` files, then obtain a list of feeds from the root source directory.
allFeeds = GetFeeds(() => dotnet.GetNugetFeedsFromFolder(this.fileProvider.SourceDir.FullName)).ToHashSet();
logger.LogDebug("No Nuget feeds found in nuget.config files.");
}

logger.LogInfo($"Found {allFeeds.Count} Nuget feeds (with inherited ones) in nuget.config files: {string.Join(", ", allFeeds.OrderBy(f => f))}");

return (explicitFeeds, allFeeds);
Copilot is powered by AI and may make mistakes. Always verify output.
Comment on lines +831 to +834
catch (Exception exc)
{
logger.LogWarning($"Failed to get directory of '{config}': {exc}");
}

Check notice

Code scanning / CodeQL

Generic catch clause Note

Generic catch clause.

Copilot Autofix

AI 4 months ago

To fix the problem, we should catch only specific exceptions that are relevant to the operation being performed. In this case, since the code is dealing with file I/O operations, we should catch exceptions such as IOException and UnauthorizedAccessException. This will ensure that only relevant exceptions are caught, and other exceptions are not unintentionally masked.

  • Identify the specific exceptions that are relevant to the file I/O operations.
  • Replace the generic catch (Exception exc) block with specific catch blocks for IOException and UnauthorizedAccessException.
  • Ensure that the logging functionality remains the same to provide useful information in case of an exception.
Suggested changeset 1
csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/NugetPackageRestorer.cs

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/NugetPackageRestorer.cs b/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/NugetPackageRestorer.cs
--- a/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/NugetPackageRestorer.cs
+++ b/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/NugetPackageRestorer.cs
@@ -830,5 +830,9 @@
                         }
-                        catch (Exception exc)
+                        catch (IOException ioExc)
                         {
-                            logger.LogWarning($"Failed to get directory of '{config}': {exc}");
+                            logger.LogWarning($"Failed to get directory of '{config}' due to I/O error: {ioExc}");
+                        }
+                        catch (UnauthorizedAccessException authExc)
+                        {
+                            logger.LogWarning($"Failed to get directory of '{config}' due to unauthorized access: {authExc}");
                         }
EOF
@@ -830,5 +830,9 @@
}
catch (Exception exc)
catch (IOException ioExc)
{
logger.LogWarning($"Failed to get directory of '{config}': {exc}");
logger.LogWarning($"Failed to get directory of '{config}' due to I/O error: {ioExc}");
}
catch (UnauthorizedAccessException authExc)
{
logger.LogWarning($"Failed to get directory of '{config}' due to unauthorized access: {authExc}");
}
Copilot is powered by AI and may make mistakes. Always verify output.
@dilanbhalla dilanbhalla changed the title Sync Main Sync Main (autogenerated) Apr 8, 2025
@dilanbhalla dilanbhalla closed this Apr 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.