Skip to content

Commit a4e3bcc

Browse files
committed
feat: wrap registration errors in OperatorException
1 parent 14705c5 commit a4e3bcc

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/DefaultEventSourceManager.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import io.fabric8.kubernetes.client.CustomResource;
55
import io.fabric8.kubernetes.client.dsl.MixedOperation;
66
import io.fabric8.kubernetes.client.dsl.Resource;
7+
import io.javaoperatorsdk.operator.OperatorException;
78
import io.javaoperatorsdk.operator.api.ResourceController;
89
import io.javaoperatorsdk.operator.api.config.ControllerConfiguration;
910
import io.javaoperatorsdk.operator.processing.CustomResourceCache;
@@ -69,7 +70,8 @@ public void close() {
6970
}
7071

7172
@Override
72-
public final void registerEventSource(String name, EventSource eventSource) {
73+
public final void registerEventSource(String name, EventSource eventSource)
74+
throws OperatorException {
7375
Objects.requireNonNull(eventSource, "EventSource must not be null");
7476

7577
try {
@@ -81,6 +83,12 @@ public final void registerEventSource(String name, EventSource eventSource) {
8183
eventSources.put(name, eventSource);
8284
eventSource.setEventHandler(defaultEventHandler);
8385
eventSource.start();
86+
} catch (Throwable e) {
87+
if (e instanceof IllegalStateException) {
88+
// leave untouched
89+
throw e;
90+
}
91+
throw new OperatorException("Couldn't register event source named '" + name + "'", e);
8492
} finally {
8593
lock.unlock();
8694
}

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/EventSourceManager.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.javaoperatorsdk.operator.processing.event;
22

3+
import io.javaoperatorsdk.operator.OperatorException;
34
import java.io.Closeable;
45
import java.util.Map;
56
import java.util.Optional;
@@ -13,8 +14,10 @@ public interface EventSourceManager extends Closeable {
1314
* @param eventSource the {@link EventSource} to register
1415
* @throws IllegalStateException if an {@link EventSource} with the same name is already
1516
* registered.
17+
* @throws OperatorException if an error occurred during the registration process
1618
*/
17-
void registerEventSource(String name, EventSource eventSource);
19+
void registerEventSource(String name, EventSource eventSource)
20+
throws IllegalStateException, OperatorException;
1821

1922
/**
2023
* Remove the {@link EventSource} identified by the given <code>name</code> from the event

0 commit comments

Comments
 (0)