Skip to content

Commit 911ace8

Browse files
committed
Implemented argument exceptions for argument errors
In a previous commit, I replaced most exceptions in the mapping services with the new `MappingServiceException`, with the idea that implementors could easily catch any expected exception with one specific class. That rationale generally makes sense, but there is some room for nuance. For example, the exception thrown by the `HierarchicalTopicMappingService`'s `GetHierarchicalRoot()` method is thrown in direct response to invalid data being passed to that method. In that case, an `ArgumentNullException` (if the parameter was explicitly nulled out) or an `ArgumentOutOfRangeException` (if it refers to an invalid topic path) make more sense. We _might_ consider replacing the latter with a subclass of `MappingServiceException` in the future to take advantage of the original rationale, but it should definitely be a class that sends a clear signal to the caller that the parameter value that they either passed, or the default value, is invalid. It's worth noting that this scenario should be rare. It only calls `defaultRoot` as a fallback for scenarios where a page doesn't have a topic associated with it—such as a 404 page—and even then, the default of `Root:Web` is expected to be valid for _most_ implementations.
1 parent bc9b7bc commit 911ace8

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

OnTopic/Mapping/Hierarchical/HierarchicalTopicMappingService{T}.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ ITopicMappingService topicMappingService
8686
\-----------------------------------------------------------------------------------------------------------------------*/
8787
if (navigationRootTopic is null) {
8888
if (String.IsNullOrEmpty(defaultRoot)) {
89-
throw new TopicMappingException(
89+
throw new ArgumentNullException(
9090
$"The current route could not be resolved to a topic and the {nameof(defaultRoot)} was not set."
9191
);
9292
}
@@ -97,7 +97,7 @@ ITopicMappingService topicMappingService
9797
| Handle error state
9898
\-----------------------------------------------------------------------------------------------------------------------*/
9999
if (navigationRootTopic is null) {
100-
throw new TopicMappingException(
100+
throw new ArgumentOutOfRangeException(
101101
$"Neither the current route nor the {nameof(defaultRoot)} parameter of {defaultRoot} could be resolved to a topic."
102102
);
103103
}

0 commit comments

Comments
 (0)