Skip to content

Commit

Permalink
Merge pull request #10812 from rainersigwald/callerargumentexpression
Browse files Browse the repository at this point in the history
Use CallerArgumentExpression for internal assert-like constructs
  • Loading branch information
rainersigwald authored Nov 5, 2024
2 parents a6b18fc + 5b7ef3c commit d8d42ef
Show file tree
Hide file tree
Showing 200 changed files with 718 additions and 698 deletions.
8 changes: 4 additions & 4 deletions src/Build/BackEnd/BuildManager/BuildManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ public BuildManager()
/// </summary>
public BuildManager(string hostName)
{
ErrorUtilities.VerifyThrowArgumentNull(hostName, nameof(hostName));
ErrorUtilities.VerifyThrowArgumentNull(hostName);
_hostName = hostName;
_buildManagerState = BuildManagerState.Idle;
_buildSubmissions = new Dictionary<int, BuildSubmissionBase>();
Expand Down Expand Up @@ -888,7 +888,7 @@ private BuildSubmissionBase<TRequestData, TResultData> PendBuildRequest<TRequest
{
lock (_syncLock)
{
ErrorUtilities.VerifyThrowArgumentNull(requestData, nameof(requestData));
ErrorUtilities.VerifyThrowArgumentNull(requestData);
ErrorIfState(BuildManagerState.WaitingForBuildToComplete, "WaitingForEndOfBuild");
ErrorIfState(BuildManagerState.Idle, "NoBuildInProgress");
VerifyStateInternal(BuildManagerState.Building);
Expand Down Expand Up @@ -1230,7 +1230,7 @@ TComponent IBuildComponentHost.GetComponent<TComponent>(BuildComponentType type)
[SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling", Justification = "Complex class might need refactoring to separate scheduling elements from submission elements.")]
private void ExecuteSubmission(BuildSubmission submission, bool allowMainThreadBuild)
{
ErrorUtilities.VerifyThrowArgumentNull(submission, nameof(submission));
ErrorUtilities.VerifyThrowArgumentNull(submission);
ErrorUtilities.VerifyThrow(!submission.IsCompleted, "Submission already complete.");

BuildRequestConfiguration? resolvedConfiguration = null;
Expand Down Expand Up @@ -3163,7 +3163,7 @@ private bool ReuseOldCaches(string[] inputCacheFiles)
{
Debug.Assert(Monitor.IsEntered(_syncLock));

ErrorUtilities.VerifyThrowInternalNull(inputCacheFiles, nameof(inputCacheFiles));
ErrorUtilities.VerifyThrowInternalNull(inputCacheFiles);
ErrorUtilities.VerifyThrow(_configCache == null, "caches must not be set at this point");
ErrorUtilities.VerifyThrow(_resultsCache == null, "caches must not be set at this point");

Expand Down
4 changes: 2 additions & 2 deletions src/Build/BackEnd/BuildManager/BuildParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ public BuildParameters()
/// <param name="projectCollection">The ProjectCollection from which the BuildParameters should populate itself.</param>
public BuildParameters(ProjectCollection projectCollection)
{
ErrorUtilities.VerifyThrowArgumentNull(projectCollection, nameof(projectCollection));
ErrorUtilities.VerifyThrowArgumentNull(projectCollection);

Initialize(new PropertyDictionary<ProjectPropertyInstance>(projectCollection.EnvironmentProperties), projectCollection.ProjectRootElementCache, new ToolsetProvider(projectCollection.Toolsets));

Expand All @@ -265,7 +265,7 @@ private BuildParameters(ITranslator translator)
/// </summary>
internal BuildParameters(BuildParameters other, bool resetEnvironment = false)
{
ErrorUtilities.VerifyThrowInternalNull(other, nameof(other));
ErrorUtilities.VerifyThrowInternalNull(other);

_buildId = other._buildId;
_culture = other._culture;
Expand Down
10 changes: 5 additions & 5 deletions src/Build/BackEnd/BuildManager/BuildRequestData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public BuildRequestData(ProjectInstance projectInstance, string[] targetsToBuild
public BuildRequestData(ProjectInstance projectInstance, string[] targetsToBuild, HostServices? hostServices, BuildRequestDataFlags flags, IEnumerable<string>? propertiesToTransfer)
: this(targetsToBuild, hostServices, flags, projectInstance.FullPath)
{
ErrorUtilities.VerifyThrowArgumentNull(projectInstance, nameof(projectInstance));
ErrorUtilities.VerifyThrowArgumentNull(projectInstance);

foreach (string targetName in targetsToBuild)
{
Expand Down Expand Up @@ -93,7 +93,7 @@ public BuildRequestData(ProjectInstance projectInstance, string[] targetsToBuild
public BuildRequestData(ProjectInstance projectInstance, string[] targetsToBuild, HostServices? hostServices, BuildRequestDataFlags flags, IEnumerable<string>? propertiesToTransfer, RequestedProjectState requestedProjectState)
: this(projectInstance, targetsToBuild, hostServices, flags, propertiesToTransfer)
{
ErrorUtilities.VerifyThrowArgumentNull(requestedProjectState, nameof(requestedProjectState));
ErrorUtilities.VerifyThrowArgumentNull(requestedProjectState);

RequestedProjectState = requestedProjectState;
}
Expand Down Expand Up @@ -127,7 +127,7 @@ public BuildRequestData(string projectFullPath, IDictionary<string, string?> glo
RequestedProjectState requestedProjectState)
: this(projectFullPath, globalProperties, toolsVersion, targetsToBuild, hostServices, flags)
{
ErrorUtilities.VerifyThrowArgumentNull(requestedProjectState, nameof(requestedProjectState));
ErrorUtilities.VerifyThrowArgumentNull(requestedProjectState);

RequestedProjectState = requestedProjectState;
}
Expand All @@ -144,8 +144,8 @@ public BuildRequestData(string projectFullPath, IDictionary<string, string?> glo
public BuildRequestData(string projectFullPath, IDictionary<string, string?> globalProperties, string? toolsVersion, string[] targetsToBuild, HostServices? hostServices, BuildRequestDataFlags flags)
: this(targetsToBuild, hostServices, flags, FileUtilities.NormalizePath(projectFullPath)!)
{
ErrorUtilities.VerifyThrowArgumentLength(projectFullPath, nameof(projectFullPath));
ErrorUtilities.VerifyThrowArgumentNull(globalProperties, nameof(globalProperties));
ErrorUtilities.VerifyThrowArgumentLength(projectFullPath);
ErrorUtilities.VerifyThrowArgumentNull(globalProperties);

GlobalPropertiesDictionary = new PropertyDictionary<ProjectPropertyInstance>(globalProperties.Count);
foreach (KeyValuePair<string, string?> propertyPair in globalProperties)
Expand Down
2 changes: 1 addition & 1 deletion src/Build/BackEnd/BuildManager/BuildRequestDataBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ protected BuildRequestDataBase(
BuildRequestDataFlags flags,
HostServices? hostServices)
{
ErrorUtilities.VerifyThrowArgumentNull(targetNames, nameof(targetNames));
ErrorUtilities.VerifyThrowArgumentNull(targetNames);
foreach (string targetName in targetNames)
{
ErrorUtilities.VerifyThrowArgumentNull(targetName, "target");
Expand Down
4 changes: 2 additions & 2 deletions src/Build/BackEnd/BuildManager/BuildSubmission.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public abstract class BuildSubmissionBase<TRequestData, TResultData> : BuildSubm
protected internal BuildSubmissionBase(BuildManager buildManager, int submissionId, TRequestData requestData)
: base(buildManager, submissionId)
{
ErrorUtilities.VerifyThrowArgumentNull(requestData, nameof(requestData));
ErrorUtilities.VerifyThrowArgumentNull(requestData);
BuildRequestData = requestData;
}

Expand Down Expand Up @@ -77,7 +77,7 @@ private protected void ExecuteAsync(
/// </summary>
internal void CompleteResults(TResultData result)
{
ErrorUtilities.VerifyThrowArgumentNull(result, nameof(result));
ErrorUtilities.VerifyThrowArgumentNull(result);
CheckResultValidForCompletion(result);

BuildResult ??= result;
Expand Down
2 changes: 1 addition & 1 deletion src/Build/BackEnd/BuildManager/BuildSubmissionBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public abstract class BuildSubmissionBase
/// </summary>
protected internal BuildSubmissionBase(BuildManager buildManager, int submissionId)
{
ErrorUtilities.VerifyThrowArgumentNull(buildManager, nameof(buildManager));
ErrorUtilities.VerifyThrowArgumentNull(buildManager);

BuildManager = buildManager;
SubmissionId = submissionId;
Expand Down
4 changes: 2 additions & 2 deletions src/Build/BackEnd/BuildManager/CacheAggregator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public CacheAggregator(Func<int> nextConfigurationId)

public void Add(IConfigCache configCache, IResultsCache resultsCache)
{
ErrorUtilities.VerifyThrowInternalNull(configCache, nameof(configCache));
ErrorUtilities.VerifyThrowInternalNull(resultsCache, nameof(resultsCache));
ErrorUtilities.VerifyThrowInternalNull(configCache);
ErrorUtilities.VerifyThrowInternalNull(resultsCache);
ErrorUtilities.VerifyThrow(!_aggregated, "Cannot add after aggregation");

_inputCaches.Add((configCache, resultsCache));
Expand Down
6 changes: 3 additions & 3 deletions src/Build/BackEnd/BuildManager/CacheSerialization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static string SerializeCaches(
string outputCacheFile,
ProjectIsolationMode projectIsolationMode)
{
ErrorUtilities.VerifyThrowInternalNull(outputCacheFile, nameof(outputCacheFile));
ErrorUtilities.VerifyThrowInternalNull(outputCacheFile);

try
{
Expand Down Expand Up @@ -127,8 +127,8 @@ public static (IConfigCache ConfigCache, IResultsCache ResultsCache, Exception e
translator.Translate(ref resultsCache);
}

ErrorUtilities.VerifyThrowInternalNull(configCache, nameof(configCache));
ErrorUtilities.VerifyThrowInternalNull(resultsCache, nameof(resultsCache));
ErrorUtilities.VerifyThrowInternalNull(configCache);
ErrorUtilities.VerifyThrowInternalNull(resultsCache);

return (configCache, resultsCache, null);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Build/BackEnd/Client/MSBuildClientPacketPump.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ internal sealed class MSBuildClientPacketPump : INodePacketHandler, INodePacketF

public MSBuildClientPacketPump(Stream stream)
{
ErrorUtilities.VerifyThrowArgumentNull(stream, nameof(stream));
ErrorUtilities.VerifyThrowArgumentNull(stream);

_stream = stream;
_isServerDisconnecting = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ public void ReportConfigurationResponse(BuildRequestConfigurationResponse respon
/// <param name="host">The host.</param>
public void InitializeComponent(IBuildComponentHost host)
{
ErrorUtilities.VerifyThrowArgumentNull(host, nameof(host));
ErrorUtilities.VerifyThrowArgumentNull(host);
ErrorUtilities.VerifyThrow(_componentHost == null, "BuildRequestEngine already initialized!");
_componentHost = host;
_configCache = (IConfigCache)host.GetComponent(BuildComponentType.ConfigCache);
Expand Down Expand Up @@ -1330,7 +1330,7 @@ private int GetNextBuildRequestId()
private void IssueConfigurationRequest(BuildRequestConfiguration config)
{
ErrorUtilities.VerifyThrow(config.WasGeneratedByNode, "InvalidConfigurationId");
ErrorUtilities.VerifyThrowArgumentNull(config, nameof(config));
ErrorUtilities.VerifyThrowArgumentNull(config);
ErrorUtilities.VerifyThrow(_unresolvedConfigurations.HasConfiguration(config.ConfigurationId), "NoUnresolvedConfiguration");
TraceEngine("Issuing configuration request for node config {0}", config.ConfigurationId);
RaiseNewConfigurationRequest(config);
Expand All @@ -1342,7 +1342,7 @@ private void IssueConfigurationRequest(BuildRequestConfiguration config)
/// <param name="blocker">The information about why the request is blocked.</param>
private void IssueBuildRequest(BuildRequestBlocker blocker)
{
ErrorUtilities.VerifyThrowArgumentNull(blocker, nameof(blocker));
ErrorUtilities.VerifyThrowArgumentNull(blocker);

if (blocker.BuildRequests == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ internal class BuildRequestEntry
/// <param name="requestConfiguration">The build request configuration.</param>
internal BuildRequestEntry(BuildRequest request, BuildRequestConfiguration requestConfiguration)
{
ErrorUtilities.VerifyThrowArgumentNull(request, nameof(request));
ErrorUtilities.VerifyThrowArgumentNull(requestConfiguration, nameof(requestConfiguration));
ErrorUtilities.VerifyThrowArgumentNull(request);
ErrorUtilities.VerifyThrowArgumentNull(requestConfiguration);
ErrorUtilities.VerifyThrow(requestConfiguration.ConfigurationId == request.ConfigurationId, "Configuration id mismatch");

GlobalLock = new Object();
Expand Down Expand Up @@ -303,7 +303,7 @@ public void ReportResult(BuildResult result)
{
lock (GlobalLock)
{
ErrorUtilities.VerifyThrowArgumentNull(result, nameof(result));
ErrorUtilities.VerifyThrowArgumentNull(result);
ErrorUtilities.VerifyThrow(State == BuildRequestEntryState.Waiting || _outstandingRequests == null, "Entry must be in the Waiting state to report results, or we must have flushed our requests due to an error. Config: {0} State: {1} Requests: {2}", RequestConfiguration.ConfigurationId, State, _outstandingRequests != null);

// If the matching request is in the issue list, remove it so we don't try to ask for it to be built.
Expand Down Expand Up @@ -471,7 +471,7 @@ public void Complete(BuildResult result)
{
lock (GlobalLock)
{
ErrorUtilities.VerifyThrowArgumentNull(result, nameof(result));
ErrorUtilities.VerifyThrowArgumentNull(result);
ErrorUtilities.VerifyThrow(Result == null, "Entry already Completed.");

// If this request is determined to be a success, then all outstanding items must have been taken care of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public FullyQualifiedBuildRequest(
bool skipStaticGraphIsolationConstraints = false,
BuildRequestDataFlags flags = BuildRequestDataFlags.None)
{
ErrorUtilities.VerifyThrowArgumentNull(config, nameof(config));
ErrorUtilities.VerifyThrowArgumentNull(targets, nameof(targets));
ErrorUtilities.VerifyThrowArgumentNull(config);
ErrorUtilities.VerifyThrowArgumentNull(targets);

Config = config;
Targets = targets;
Expand Down
8 changes: 4 additions & 4 deletions src/Build/BackEnd/Components/Caching/ConfigCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public BuildRequestConfiguration this[int configId]
/// <param name="config">The configuration to add.</param>
public void AddConfiguration(BuildRequestConfiguration config)
{
ErrorUtilities.VerifyThrowArgumentNull(config, nameof(config));
ErrorUtilities.VerifyThrowArgumentNull(config);
ErrorUtilities.VerifyThrow(config.ConfigurationId != 0, "Invalid configuration ID");

lock (_lockObject)
Expand Down Expand Up @@ -107,7 +107,7 @@ public void RemoveConfiguration(int configId)
/// <returns>A matching configuration if one exists, null otherwise.</returns>
public BuildRequestConfiguration GetMatchingConfiguration(BuildRequestConfiguration config)
{
ErrorUtilities.VerifyThrowArgumentNull(config, nameof(config));
ErrorUtilities.VerifyThrowArgumentNull(config);
return GetMatchingConfiguration(new ConfigurationMetadata(config));
}

Expand All @@ -118,7 +118,7 @@ public BuildRequestConfiguration GetMatchingConfiguration(BuildRequestConfigurat
/// <returns>A matching configuration if one exists, null otherwise.</returns>
public BuildRequestConfiguration GetMatchingConfiguration(ConfigurationMetadata configMetadata)
{
ErrorUtilities.VerifyThrowArgumentNull(configMetadata, nameof(configMetadata));
ErrorUtilities.VerifyThrowArgumentNull(configMetadata);
lock (_lockObject)
{
if (!_configurationIdsByMetadata.TryGetValue(configMetadata, out int configId))
Expand Down Expand Up @@ -341,7 +341,7 @@ System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
/// <param name="host">The build component host.</param>
public void InitializeComponent(IBuildComponentHost host)
{
ErrorUtilities.VerifyThrowArgumentNull(host, nameof(host));
ErrorUtilities.VerifyThrowArgumentNull(host);
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions src/Build/BackEnd/Components/Caching/ResultsCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ public void WriteResultsToDisk()
/// <param name="host">The component host.</param>
public void InitializeComponent(IBuildComponentHost host)
{
ErrorUtilities.VerifyThrowArgumentNull(host, nameof(host));
ErrorUtilities.VerifyThrowArgumentNull(host);
}

/// <summary>
Expand Down Expand Up @@ -350,7 +350,7 @@ private static bool CheckResults(BuildResult result, List<string> targets, HashS
/// <param name="buildResult">The candidate build result.</param>
/// <returns>True if the flags and project state filter of the build request is compatible with the build result.</returns>
private static bool AreBuildResultFlagsCompatible(BuildRequest buildRequest, BuildResult buildResult)
{
{
if (buildResult.BuildRequestDataFlags is null)
{
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ internal class NodeEndpointInProc : INodeEndpoint
/// <param name="host">The component host.</param>
private NodeEndpointInProc(EndpointMode commMode, IBuildComponentHost host)
{
ErrorUtilities.VerifyThrowArgumentNull(host, nameof(host));
ErrorUtilities.VerifyThrowArgumentNull(host);

_status = LinkStatus.Inactive;
_mode = commMode;
Expand Down Expand Up @@ -162,7 +162,7 @@ public LinkStatus LinkStatus
/// <param name="factory">Unused</param>
public void Listen(INodePacketFactory factory)
{
ErrorUtilities.VerifyThrowInternalNull(factory, nameof(factory));
ErrorUtilities.VerifyThrowInternalNull(factory);
_packetFactory = factory;

// Initialize our thread in async mode so we are ready when the Node-side endpoint "connects".
Expand All @@ -180,7 +180,7 @@ public void Listen(INodePacketFactory factory)
/// <param name="factory">Unused</param>
public void Connect(INodePacketFactory factory)
{
ErrorUtilities.VerifyThrowInternalNull(factory, nameof(factory));
ErrorUtilities.VerifyThrowInternalNull(factory);
_packetFactory = factory;

// Set up asynchronous packet pump, if necessary.
Expand Down Expand Up @@ -331,7 +331,7 @@ private void ChangeLinkStatus(LinkStatus newStatus)
/// <param name="packet">The packet to be transmitted.</param>
private void EnqueuePacket(INodePacket packet)
{
ErrorUtilities.VerifyThrowArgumentNull(packet, nameof(packet));
ErrorUtilities.VerifyThrowArgumentNull(packet);
ErrorUtilities.VerifyThrow(_mode == EndpointMode.Asynchronous, "EndPoint mode is synchronous, should be asynchronous");
ErrorUtilities.VerifyThrow(_packetQueue != null, "packetQueue is null");
ErrorUtilities.VerifyThrow(_packetAvailable != null, "packetAvailable is null");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public void ShutdownComponent()
public void SendData(int nodeId, INodePacket packet)
{
ErrorUtilities.VerifyThrowArgumentOutOfRange(nodeId == _inProcNodeId, "node");
ErrorUtilities.VerifyThrowArgumentNull(packet, nameof(packet));
ErrorUtilities.VerifyThrowArgumentNull(packet);

if (_inProcNode == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ internal static Handshake GetHandshake(bool enableNodeReuse, bool enableLowPrior
/// </summary>
public IList<NodeInfo> CreateNodes(int nextNodeId, INodePacketFactory factory, Func<NodeInfo, NodeConfiguration> configurationFactory, int numberOfNodesToCreate)
{
ErrorUtilities.VerifyThrowArgumentNull(factory, nameof(factory));
ErrorUtilities.VerifyThrowArgumentNull(factory);

// This can run concurrently. To be properly detect internal bug when we create more nodes than allowed
// we add into _nodeContexts premise of future node and verify that it will not cross limits.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ protected IBuildComponentHost ComponentHost
/// <param name="packet">The packet to send.</param>
protected void SendData(NodeContext context, INodePacket packet)
{
ErrorUtilities.VerifyThrowArgumentNull(packet, nameof(packet));
ErrorUtilities.VerifyThrowArgumentNull(packet);
context.SendData(packet);
}

Expand Down
Loading

0 comments on commit d8d42ef

Please sign in to comment.