Skip to content

Commit c4d2fe4

Browse files
Updated SettingsHelper to not throw exception if the settings file can not be read
#3902
1 parent f5843ae commit c4d2fe4

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

StyleCop.Analyzers/StyleCop.Analyzers/Settings/SettingsHelper.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,18 @@ private static SettingsFile GetSettingsFile(AnalyzerOptions options, Func<Source
275275
if (IsStyleCopSettingsFile(additionalFile.Path))
276276
{
277277
SourceText additionalTextContent = additionalFile.GetText(cancellationToken);
278-
var content = getJsonValue(additionalTextContent);
279-
return new SettingsFile(additionalFile.Path, content);
278+
if (additionalTextContent != null)
279+
{
280+
var content = getJsonValue(additionalTextContent);
281+
return new SettingsFile(additionalFile.Path, content);
282+
}
283+
else
284+
{
285+
// Failed to read the file! Probably because of a broken link.
286+
var content = new Lazy<JsonValue>(() => throw new InvalidSettingsException(
287+
$"Settings file at '{additionalFile.Path}' could not be read"));
288+
return new SettingsFile(additionalFile.Path, content);
289+
}
280290
}
281291
}
282292

0 commit comments

Comments
 (0)