Skip to content

Commit d749804

Browse files
authored
Merge pull request #118 from scijava/scijava-ops-engine/helpful-matching-exceptions
Provide more helpful Op matching exceptions
2 parents 18645d2 + b2a3654 commit d749804

3 files changed

Lines changed: 12 additions & 11 deletions

File tree

‎scijava-ops-engine/src/main/java/org/scijava/ops/engine/matcher/impl/DefaultOpMatcher.java‎

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,18 @@ public OpCandidate match(MatchingConditions conditions, OpEnvironment env) {
7171
}
7272

7373
// in the case of no matches, throw an agglomerated exception
74-
throw agglomeratedException(exceptions);
74+
throw agglomeratedException(conditions.request(), exceptions, env);
7575
}
7676

77-
private OpMatchingException agglomeratedException(
78-
List<OpMatchingException> list)
79-
{
80-
OpMatchingException agglomerated = new OpMatchingException(
81-
"No MatchingRoutine was able to produce a match!");
82-
for (int i = 0; i < list.size(); i++) {
83-
agglomerated.addSuppressed(list.get(i));
84-
}
77+
private OpMatchingException agglomeratedException( //
78+
final OpRequest request, //
79+
final List<OpMatchingException> list, //
80+
final OpEnvironment env //
81+
) {
82+
// Develop help message
83+
var msg = "No match found! Perhaps you meant: \n" + env.help(request);
84+
OpMatchingException agglomerated = new OpMatchingException(msg);
85+
list.forEach(agglomerated::addSuppressed);
8586
return agglomerated;
8687
}
8788
}

‎scijava-ops-engine/src/main/java/org/scijava/ops/engine/matcher/simplify/SimplificationUtils.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ public static SimplifiedOpInfo simplifyInfo(OpEnvironment env, OpInfo info) {
205205
.opType()));
206206
if (ioIndex > -1) {
207207
var nil = Nil.of(outType(info.outputType(), outSimplifier));
208-
var copier = env.unary("engine.copy").inType(nil).outType(nil).computer();
208+
var copier = env.unary("engine.copy", h).inType(nil).outType(nil).computer();
209209
copyOp = org.scijava.ops.api.Ops.rich(copier);
210210
}
211211
return new SimplifiedOpInfo(info, inFocusers, outSimplifier, copyOp);

‎scijava-ops-engine/src/test/java/org/scijava/ops/engine/matcher/OpMatchingExceptionTest.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public void duplicateErrorRegressionTest() {
8080
}
8181
catch (OpMatchingException e) {
8282
Assertions.assertTrue(e.getMessage().startsWith(
83-
"No MatchingRoutine was able to produce a match!"));
83+
"No match found!"));
8484
Assertions.assertTrue(Arrays.stream(e.getSuppressed()).anyMatch(s -> s
8585
.getMessage().startsWith("Multiple 'test.duplicateOp/" +
8686
"java.util.function.Function<java.lang.Double, java.lang.Double>' " +

0 commit comments

Comments
 (0)