Skip to content

Commit ae06854

Browse files
committed
Add UnnamedOpException
Thrown during OpInfo validation when no names are provided for an op
1 parent 55a0a7a commit ae06854

2 files changed

Lines changed: 50 additions & 4 deletions

File tree

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*-
2+
* #%L
3+
* SciJava Operations Engine: a framework for reusable algorithms.
4+
* %%
5+
* Copyright (C) 2016 - 2023 SciJava developers.
6+
* %%
7+
* Redistribution and use in source and binary forms, with or without
8+
* modification, are permitted provided that the following conditions are met:
9+
*
10+
* 1. Redistributions of source code must retain the above copyright notice,
11+
* this list of conditions and the following disclaimer.
12+
* 2. Redistributions in binary form must reproduce the above copyright notice,
13+
* this list of conditions and the following disclaimer in the documentation
14+
* and/or other materials provided with the distribution.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26+
* POSSIBILITY OF SUCH DAMAGE.
27+
* #L%
28+
*/
29+
30+
package org.scijava.ops.engine.exceptions.impl;
31+
32+
import org.scijava.ops.engine.exceptions.InvalidOpException;
33+
34+
/**
35+
* An {@link InvalidOpException} arising when no names are given for the Op
36+
*
37+
* @author Mark Hiner
38+
*/
39+
public class UnnamedOpException extends InvalidOpException {
40+
41+
public UnnamedOpException(Object op) {
42+
super("No names declared for Op: " + op + " - all Ops must have at least one name");
43+
}
44+
}

‎scijava/scijava-ops-engine/src/main/java/org/scijava/ops/engine/util/Infos.java‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,14 @@
3232
import java.lang.reflect.ParameterizedType;
3333
import java.lang.reflect.Type;
3434
import java.lang.reflect.TypeVariable;
35-
import java.util.ArrayList;
36-
import java.util.Arrays;
37-
import java.util.List;
38-
import java.util.Optional;
35+
import java.util.*;
3936
import java.util.stream.Collectors;
4037

4138
import org.scijava.ops.api.OpInfo;
4239
import org.scijava.ops.engine.OpDependencyMember;
40+
import org.scijava.ops.engine.exceptions.InvalidOpException;
4341
import org.scijava.ops.engine.exceptions.impl.MultipleOutputsOpException;
42+
import org.scijava.ops.engine.exceptions.impl.UnnamedOpException;
4443
import org.scijava.struct.ItemIO;
4544
import org.scijava.struct.Member;
4645
import org.scijava.types.Types;
@@ -96,6 +95,9 @@ public static void validate(final OpInfo info) {
9695
if (numOutputs > 1) {
9796
throw new MultipleOutputsOpException(info.implementationName());
9897
}
98+
if (Objects.isNull(info.names()) || info.names().isEmpty()) {
99+
throw new UnnamedOpException(info.implementationName());
100+
}
99101
}
100102

101103
/**

0 commit comments

Comments
 (0)