Skip to content

Commit 5138dea

Browse files
committed
Swallow TopicNotFoundException in GetContentTypeDescriptors()
When the database is empty, the call to `ITopicRepository.Load("Configuration")` is _expected_ to return a `TopicNotFoundException`. As part of the empty repository support, however, we don't want this to prevent rendering of the application when `GetContentTypeDescriptors()` is called. As such, we're swalling this exception. Unfortunately, this is introducing a `CA1031`, which happens when capturing a general exception. The only problem is that this isn't a general exception. This used to be a bug in Roslyn Code Analyzers, but it was fixed in 2.9.7. It may have been reintroduced in 3.0.0? Regardless, I've reported the issue to the Roslyn team, but in the meanwhile we'll need to suppress the issue.
1 parent 2300e69 commit 5138dea

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

OnTopic/GlobalSuppressions.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,8 @@
33
// Project-level suppressions either have no target or are given
44
// a specific target and scoped to a namespace, type, member, etc.
55

6-
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Globalization", "CA1307:Specify StringComparison", Justification = "Invalid overload; known bug in code analysis", Scope = "member", Target = "~P:OnTopic.Metadata.AttributeDescriptor.Configuration")]
7-
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Globalization", "CA1307:Specify StringComparison", Justification = "Invalid overload; known bug in code analysis", Scope = "member", Target = "~M:OnTopic.Topic.GetWebPath~System.String")]
6+
using System.Diagnostics.CodeAnalysis;
7+
8+
[assembly: SuppressMessage("Globalization", "CA1307:Specify StringComparison", Justification = "Invalid overload; known bug in code analysis", Scope = "member", Target = "~P:OnTopic.Metadata.AttributeDescriptor.Configuration")]
9+
[assembly: SuppressMessage("Globalization", "CA1307:Specify StringComparison", Justification = "Invalid overload; known bug in code analysis", Scope = "member", Target = "~M:OnTopic.Topic.GetWebPath~System.String")]
10+
[assembly: SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "False positive; apparent bug in code analysis", Scope = "member", Target = "~M:OnTopic.Repositories.TopicRepositoryBase.GetContentTypeDescriptors~OnTopic.Metadata.ContentTypeDescriptorCollection")]

OnTopic/Repositories/TopicRepositoryBase.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,14 @@ public virtual ContentTypeDescriptorCollection GetContentTypeDescriptors() {
6767
/*----------------------------------------------------------------------------------------------------------------------
6868
| Load configuration data
6969
\---------------------------------------------------------------------------------------------------------------------*/
70-
var configuration = Load("Configuration");
70+
var configuration = (Topic?)null;
71+
72+
try {
73+
configuration = Load("Configuration");
74+
}
75+
catch (TopicNotFoundException) {
76+
//Swallow missing configuration, as this is an expected condition when working with a new database
77+
}
7178

7279
/*----------------------------------------------------------------------------------------------------------------------
7380
| Load root content type

0 commit comments

Comments
 (0)