Skip to content

Commit aa63b4a

Browse files
committed
Account for empty data store in GetContentTypeDescriptors()
Previously, the `GetContentTypeDescriptors()` call threw an exception if it was unable to load the `Root:Configuration:ContentTypes` from the underlying data store. That made good sense at the time. But as we've introduced the **OnTopic Data Exchange** into the **OnTopic Editor**, we now want to allow an empty database to be initialized by importing reference JSON files. This can't happen if the application throws an exception before getting to that point. To mitigate this, we've now removed these exceptions and allowed for a scenario where `GetContentTypeDescriptors()` finds no content type descriptors in the underlying data store. It's worth noting that exceptions will still be thrown in this scenario, they'll just be thrown by the `TopicRepositoryBase.Save()` method which reliesupon that cache, instead of happening as part of `GetContentTypeDescriptors()` itself. That still introduces the potential that other callers, besides `Save()`, will get an empty set, but that allows them to handle it as appropriate—e.g., ignoring it if they are alright with it, otherwise throwing an exception. Technically, this is a breaking change in that now `GetContentTypeDescriptors()` can return an empty collection instead of throwing an exception. Since the only current implementors of `TopicRepositoryBase` are part of this repository, however, and the exception wasn't previously documented, we can safely make this change without any concern over breaking implementations.
1 parent f906d26 commit aa63b4a

1 file changed

Lines changed: 2 additions & 6 deletions

File tree

OnTopic/Repositories/TopicRepositoryBase.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,10 @@ public virtual ContentTypeDescriptorCollection GetContentTypeDescriptors() {
6969
\---------------------------------------------------------------------------------------------------------------------*/
7070
var configuration = Load("Configuration");
7171

72-
Contract.Assume(configuration, $"The 'Root:Configuration' section could not be loaded from the 'ITopicRepository'.");
73-
7472
/*----------------------------------------------------------------------------------------------------------------------
7573
| Load root content type
7674
\---------------------------------------------------------------------------------------------------------------------*/
77-
var allowedContentTypes = configuration.Children.GetTopic("ContentTypes") as ContentTypeDescriptor;
78-
79-
Contract.Assume(allowedContentTypes, "Unable to load section 'Configuration:ContentTypes'.");
75+
var allowedContentTypes = configuration?.Children.GetTopic("ContentTypes") as ContentTypeDescriptor;
8076

8177
/*----------------------------------------------------------------------------------------------------------------------
8278
| Add available Content Types to the collection
@@ -107,7 +103,7 @@ public virtual ContentTypeDescriptorCollection GetContentTypeDescriptors() {
107103
/// also any descendents.
108104
/// </param>
109105
/// <returns></returns>
110-
protected virtual ContentTypeDescriptorCollection GetContentTypeDescriptors(ContentTypeDescriptor contentTypeDescriptors) {
106+
protected virtual ContentTypeDescriptorCollection GetContentTypeDescriptors(ContentTypeDescriptor? contentTypeDescriptors) {
111107

112108
/*------------------------------------------------------------------------------------------------------------------------
113109
| Initialize the collection from the repository

0 commit comments

Comments
 (0)