Skip to content

Commit 4d226ba

Browse files
committed
Warn on service failure, debug stack trace
When a service fails to load in the ServiceHelper, it now issues a one line warning message instead of an "error" with a full stack trace. The stack trace is instead logged to debug. The goal was to reduce the standard output, and avoid confusion over the error message as program execution isn't actually halted by failing to load a service.
1 parent f083858 commit 4d226ba

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,15 +152,16 @@ public <S extends Service> S loadService(final Class<S> c) {
152152
* instantiated
153153
*/
154154
public <S extends Service> S createExactService(final Class<S> c) {
155-
debug("Creating service: " + c.getName());
155+
debug("Creating service: " + c.getName(), null);
156156
try {
157157
final S service = createService(c);
158158
getContext().getServiceIndex().add(service);
159159
info("Created service: " + c.getName());
160160
return service;
161161
}
162162
catch (final Throwable t) {
163-
error("Invalid service: " + c.getName(), t);
163+
warn("Invalid service: " + c.getName());
164+
debug("Invalid service: " + c.getName(), t);
164165
}
165166
return null;
166167
}
@@ -229,6 +230,12 @@ private void info(final String msg) {
229230
final LogService log = getContext().getService(LogService.class);
230231
if (log != null) log.info(msg);
231232
}
233+
234+
/** Logs the given warning, if a {@link LogService} is available. */
235+
private void warn(final String msg) {
236+
final LogService log = getContext().getService(LogService.class);
237+
if (log != null) log.warn(msg);
238+
}
232239

233240
/** Logs the given error, if a {@link LogService} is available. */
234241
private void error(final String msg, final Throwable t) {
@@ -237,9 +244,9 @@ private void error(final String msg, final Throwable t) {
237244
}
238245

239246
/** Logs the given debug message, if a {@link LogService} is available. */
240-
private void debug(final String msg) {
247+
private void debug(final String msg, final Throwable t) {
241248
final LogService log = getContext().getService(LogService.class);
242-
if (log != null) log.debug(msg);
249+
if (log != null) log.debug(msg, t);
243250
}
244251

245252
}

0 commit comments

Comments
 (0)