Skip to content

Commit 9f6c8c1

Browse files
authored
improve: log error in NodeExecutor (#3102)
Signed-off-by: Attila Mészáros <[email protected]>
1 parent eba5dad commit 9f6c8c1

File tree

2 files changed

+53
-0
lines changed
  • operator-framework-core/src

2 files changed

+53
-0
lines changed

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/NodeExecutor.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,15 @@
1515
*/
1616
package io.javaoperatorsdk.operator.processing.dependent.workflow;
1717

18+
import org.slf4j.Logger;
19+
import org.slf4j.LoggerFactory;
20+
1821
import io.fabric8.kubernetes.api.model.HasMetadata;
1922

2023
abstract class NodeExecutor<R, P extends HasMetadata> implements Runnable {
2124

25+
private static final Logger log = LoggerFactory.getLogger(NodeExecutor.class);
26+
2227
private final DependentResourceNode<R, P> dependentResourceNode;
2328
private final AbstractWorkflowExecutor<P> workflowExecutor;
2429

@@ -37,6 +42,10 @@ public void run() {
3742
} catch (Exception e) {
3843
// Exception is required because of Kotlin
3944
workflowExecutor.handleExceptionInExecutor(dependentResourceNode, e);
45+
} catch (Error e) {
46+
// without this user would see no sign about the error
47+
log.error("java.lang.Error during execution", e);
48+
throw e;
4049
} finally {
4150
workflowExecutor.handleNodeExecutionFinish(dependentResourceNode);
4251
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright Java Operator SDK Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.javaoperatorsdk.operator.processing.dependent.workflow;
17+
18+
import java.util.concurrent.ExecutorService;
19+
import java.util.concurrent.Executors;
20+
21+
import org.junit.jupiter.api.Disabled;
22+
import org.junit.jupiter.api.Test;
23+
24+
import static org.junit.jupiter.api.Assertions.*;
25+
26+
class NodeExecutorTest {
27+
28+
private NodeExecutor errorThrowingNodeExecutor =
29+
new NodeExecutor(null, null) {
30+
@Override
31+
protected void doRun(DependentResourceNode dependentResourceNode) {
32+
throw new NoSuchFieldError();
33+
}
34+
};
35+
36+
// for manual testing only to verify you can see the log message
37+
@Disabled
38+
@Test
39+
void nodeExecutorLogsError() throws InterruptedException {
40+
ExecutorService executorService = Executors.newSingleThreadExecutor();
41+
executorService.submit(errorThrowingNodeExecutor);
42+
Thread.sleep(500);
43+
}
44+
}

0 commit comments

Comments
 (0)