Skip to content

Commit 25beaf6

Browse files
dschoctrueden
authored andcommitted
Report non-optional services' failing to initialize
This hopefully addresses the issue that some services should not clutter the log when failing to initialize (such as SCIFIO's LuraWaveService), but other services should not fail silently, such as ImageJ2's LUTService or LegacyService. From now on, we can mark the former category of services with the Optional interface and still have helpful information from the log in case essential services were not initialized (and therefore not added to the set of available services). Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent 3b6bd68 commit 25beaf6

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/main/java/org/scijava/service/ServiceHelper.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444

4545
import org.scijava.AbstractContextual;
4646
import org.scijava.Context;
47+
import org.scijava.Optional;
4748
import org.scijava.event.EventService;
4849
import org.scijava.log.LogService;
4950
import org.scijava.log.StderrLogService;
@@ -180,8 +181,15 @@ public <S extends Service> S createExactService(final Class<S> c) {
180181
}
181182
catch (final Throwable t) {
182183
if (log.isDebug()) {
184+
// when in debug mode, always give full stack trace of invalid services
183185
log.debug("Invalid service: " + c.getName(), t);
184-
} else {
186+
}
187+
else if (!Optional.class.isAssignableFrom(c)) {
188+
// for required (i.e., non-optional) services, we also dump the stack
189+
log.warn("Invalid service: " + c.getName(), t);
190+
}
191+
else {
192+
// we emit only a short warning for failing optional services
185193
log.warn("Invalid service: " + c.getName());
186194
}
187195
}

0 commit comments

Comments
 (0)