Skip to content

Commit 6679961

Browse files
committed
Slightly improve the scary missing object message
Instead of "A ___ is required but none exists", we now use the slightly less scary "A(n) ___ is required but none is available."
1 parent c720bf0 commit 6679961

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/main/java/org/scijava/widget/AbstractInputHarvester.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
package org.scijava.widget;
3131

3232
import java.util.ArrayList;
33+
import java.util.Arrays;
3334
import java.util.Collection;
3435
import java.util.List;
3536
import java.util.Set;
@@ -120,8 +121,15 @@ private <T> WidgetModel addInput(final InputPanel<P, W> inputPanel,
120121
}
121122

122123
if (item.isRequired()) {
123-
throw new ModuleException("A " + type.getSimpleName() +
124-
" is required but none exist.");
124+
final List<String> vowelSoundPrefixes = Arrays.asList(
125+
"a", "e", "i", "o", "u", "honor", "honour", "hour", "xml"
126+
);
127+
final String typeName = type.getSimpleName();
128+
final String article = vowelSoundPrefixes.stream().anyMatch(
129+
prefix -> typeName.toLowerCase().startsWith(prefix)
130+
) ? "An" : "A";
131+
throw new ModuleException(article + " " + typeName +
132+
" is required but none is available.");
125133
}
126134

127135
// item is not required; we can skip it

0 commit comments

Comments
 (0)