提交 fc80bb08 编写于 作者: K Kirill Osenkov 提交者: Andy Gocke

Avoid a first-chance FileNotFoundException when a ruleset include is not found. (#34696)

When a .ruleset file includes a non-existing ruleset reference we receive null from ResolveIncludePath and throw a FileNotFoundException, which is the immediately caught in LoadRuleSet.

We can avoid the first-chance exception and the associated allocations if we just return null. A missing ruleset is not an exceptional situation so no need to use exceptions for control flow here if we can avoid it.
上级 e65f0cb2
......@@ -55,6 +55,11 @@ public RuleSet LoadRuleSet(RuleSet parent)
try
{
path = GetIncludePath(parent);
if (path == null)
{
return null;
}
ruleSet = RuleSetProcessor.LoadFromFile(path);
}
catch (FileNotFoundException)
......@@ -78,11 +83,9 @@ public RuleSet LoadRuleSet(RuleSet parent)
private string GetIncludePath(RuleSet parent)
{
var resolvedIncludePath = ResolveIncludePath(_includePath, parent?.FilePath);
// If we still couldn't find it then throw an exception;
if (resolvedIncludePath == null)
{
throw new FileNotFoundException(string.Format(CodeAnalysisResources.FailedToResolveRuleSetName, _includePath), _includePath);
return null;
}
// Return the canonical full path
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册