Skip to content

Provide more helpful Op matching exceptions#118

Merged
gselzer merged 3 commits into
mainfrom
scijava-ops-engine/helpful-matching-exceptions
Jan 29, 2024
Merged

Provide more helpful Op matching exceptions#118
gselzer merged 3 commits into
mainfrom
scijava-ops-engine/helpful-matching-exceptions

Conversation

@gselzer

@gselzer gselzer commented Jan 12, 2024

Copy link
Copy Markdown
Member

This PR leans on the new OpEnvironment.help() API to enable more helpful OpMatchingExceptions.

This means that if the following Op call does not match:

		var list = ops.binary("math.add").input(List.of(5.0), List.of(6.0)).apply();

You will now get an error like:

org.scijava.ops.api.OpMatchingException: No match found! Perhaps you meant:
Ops:
	> math.add(
		 Inputs:
			Double input1
			Double input2
		 Outputs:
			Double output1
	)
	
	> math.add(
		 Inputs:
			Number input1
			Number input2
		 Outputs:
			Double output1
	)
	

	at org.scijava.ops.engine/org.scijava.ops.engine.matcher.impl.DefaultOpMatcher.agglomeratedException(DefaultOpMatcher.java:83)
	at org.scijava.ops.engine/org.scijava.ops.engine.matcher.impl.DefaultOpMatcher.match(DefaultOpMatcher.java:74)
	at ...

Of course, this output will change with #113, and we might want to make further alterations to the help functionality.

EDIT: Unfortunately, in SciJava Ops Image this change is being bitten by scijava/scijava#176, which means that the build increases by 2 minutes (because of one test file!). For now I'm going to try/catch this issue.

@gselzer gselzer added the enhancement New feature or request label Jan 12, 2024
@gselzer gselzer self-assigned this Jan 12, 2024
@gselzer gselzer force-pushed the scijava-ops-engine/helpful-matching-exceptions branch from 68bb3be to 71fb963 Compare January 12, 2024 22:47
@gselzer gselzer force-pushed the scijava-ops-engine/helpful-matching-exceptions branch from 71fb963 to 4ce01bf Compare January 23, 2024 15:47
The actual response leans on the OpEnvironment.help() implementation, so
we may want to edit that as needed...
@hinerm hinerm force-pushed the scijava-ops-engine/helpful-matching-exceptions branch from 4ce01bf to 62b2837 Compare January 26, 2024 20:33
var msg = "No match found!";
try {
// TODO: Remove try/catch.
msg += " Perhaps you meant: \n" + env.help(request);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

conceptually this seems useful. We'll have to see if it is in practice but I don't see any reason not to do it now.

catch (OpMatchingException e) {
Assertions.assertTrue(e.getMessage().startsWith(
"No MatchingRoutine was able to produce a match!"));
"No match found!"));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer the new wording! 👍

Since this should be fixed, we want to know of any further
StackOverflows
@gselzer gselzer marked this pull request as ready for review January 29, 2024 15:17
@gselzer gselzer merged commit d749804 into main Jan 29, 2024
@gselzer gselzer deleted the scijava-ops-engine/helpful-matching-exceptions branch January 29, 2024 15:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

No open projects

Development

Successfully merging this pull request may close these issues.

2 participants