Skip to content

Commit cf0c12f

Browse files
authored
chore: ud-container env variable for formalising the errors (#170)
Signed-off-by: adarsh0728 <[email protected]>
1 parent c3737df commit cf0c12f

File tree

11 files changed

+32
-22
lines changed

11 files changed

+32
-22
lines changed

src/main/java/io/numaproj/numaflow/batchmapper/Service.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public void onNext(MapOuterClass.MapRequest mapRequest) {
106106
// Build gRPC Status
107107
com.google.rpc.Status status = com.google.rpc.Status.newBuilder()
108108
.setCode(Code.INTERNAL.getNumber())
109-
.setMessage(ExceptionUtils.ERR_BATCH_MAP_EXCEPTION + ": " + (e.getMessage() != null ? e.getMessage() : ""))
109+
.setMessage(ExceptionUtils.getExceptionErrorString() + ": " + (e.getMessage() != null ? e.getMessage() : ""))
110110
.addDetails(Any.pack(DebugInfo.newBuilder()
111111
.setDetail(ExceptionUtils.getStackTrace(e))
112112
.build()))

src/main/java/io/numaproj/numaflow/mapper/MapSupervisorActor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ private void handleFailure(Exception e) {
114114
// Build gRPC Status
115115
com.google.rpc.Status status = com.google.rpc.Status.newBuilder()
116116
.setCode(Code.INTERNAL.getNumber())
117-
.setMessage(ExceptionUtils.ERR_MAP_EXCEPTION + ": " + (e.getMessage() != null ? e.getMessage() : ""))
117+
.setMessage(ExceptionUtils.getExceptionErrorString() + ": " + (e.getMessage() != null ? e.getMessage() : ""))
118118
.addDetails(Any.pack(DebugInfo.newBuilder()
119119
.setDetail(ExceptionUtils.getStackTrace(e))
120120
.build()))

src/main/java/io/numaproj/numaflow/servingstore/Service.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public void put(Store.PutRequest request, StreamObserver<Store.PutResponse> resp
4646
// Build gRPC Status
4747
com.google.rpc.Status status = com.google.rpc.Status.newBuilder()
4848
.setCode(Code.INTERNAL.getNumber())
49-
.setMessage(ExceptionUtils.ERR_SERVING_STORE_EXCEPTION + ": "
49+
.setMessage(ExceptionUtils.getExceptionErrorString() + ": "
5050
+ (e.getMessage() != null ? e.getMessage() : ""))
5151
.addDetails(Any.pack(DebugInfo.newBuilder()
5252
.setDetail(ExceptionUtils.getStackTrace(e))
@@ -78,7 +78,7 @@ public void get(Store.GetRequest request, StreamObserver<Store.GetResponse> resp
7878
// Build gRPC Status
7979
com.google.rpc.Status status = com.google.rpc.Status.newBuilder()
8080
.setCode(Code.INTERNAL.getNumber())
81-
.setMessage(ExceptionUtils.ERR_SERVING_STORE_EXCEPTION + ": "
81+
.setMessage(ExceptionUtils.getExceptionErrorString() + ": "
8282
+ (e.getMessage() != null ? e.getMessage() : ""))
8383
.addDetails(Any.pack(DebugInfo.newBuilder()
8484
.setDetail(ExceptionUtils.getStackTrace(e))

src/main/java/io/numaproj/numaflow/shared/ExceptionUtils.java

+17-11
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,20 @@
22

33
import java.io.PrintWriter;
44
import java.io.StringWriter;
5+
import java.util.Objects;
56

67
public class ExceptionUtils {
7-
/**
8-
* Formalized exception error strings
9-
*/
10-
public static final String ERR_SOURCE_EXCEPTION = "UDF_EXECUTION_ERROR(source)";
11-
public static final String ERR_TRANSFORMER_EXCEPTION = "UDF_EXECUTION_ERROR(transformer)";
12-
public static final String ERR_SINK_EXCEPTION = "UDF_EXECUTION_ERROR(sink)";
13-
public static final String ERR_MAP_STREAM_EXCEPTION = "UDF_EXECUTION_ERROR(mapstream)";
14-
public static final String ERR_MAP_EXCEPTION = "UDF_EXECUTION_ERROR(map)";
15-
public static final String ERR_BATCH_MAP_EXCEPTION = "UDF_EXECUTION_ERROR(batchmap)";
16-
public static final String ERR_SERVING_STORE_EXCEPTION = "UDF_EXECUTION_ERROR(servingstore)";
8+
9+
/**
10+
* UD Container Type Environment Variable
11+
*/
12+
public static final String ENV_UD_CONTAINER_TYPE = "NUMAFLOW_UD_CONTAINER_TYPE";
13+
public static final String CONTAINER_NAME = System.getenv(ENV_UD_CONTAINER_TYPE);
1714

1815
/**
1916
* Converts the stack trace of an exception into a String.
2017
*
21-
* @param e the exception to extract the stack trace from
18+
* @param t the exception to extract the stack trace from
2219
*
2320
* @return the stack trace as a String
2421
*/
@@ -30,4 +27,13 @@ public static String getStackTrace(Throwable t) {
3027
t.printStackTrace(new PrintWriter(sw));
3128
return sw.toString();
3229
}
30+
31+
/**
32+
* Returns a formalized exception error string.
33+
*
34+
* @return the formalized exception error string
35+
*/
36+
public static String getExceptionErrorString() {
37+
return "UDF_EXECUTION_ERROR(" + Objects.requireNonNullElse(CONTAINER_NAME, "unknown-container") + ")";
38+
}
3339
}

src/main/java/io/numaproj/numaflow/sinker/Service.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public void onNext(SinkOuterClass.SinkRequest request) {
108108
// Build gRPC Status
109109
com.google.rpc.Status status = com.google.rpc.Status.newBuilder()
110110
.setCode(Code.INTERNAL.getNumber())
111-
.setMessage(ExceptionUtils.ERR_SINK_EXCEPTION + ": "
111+
.setMessage(ExceptionUtils.getExceptionErrorString() + ": "
112112
+ (e.getMessage() != null ? e.getMessage() : ""))
113113
.addDetails(Any.pack(DebugInfo.newBuilder()
114114
.setDetail(ExceptionUtils.getStackTrace(e))

src/main/java/io/numaproj/numaflow/sourcer/Service.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public void onNext(SourceOuterClass.ReadRequest request) {
8888
// Build gRPC Status
8989
com.google.rpc.Status status = com.google.rpc.Status.newBuilder()
9090
.setCode(Code.INTERNAL.getNumber())
91-
.setMessage(ExceptionUtils.ERR_SOURCE_EXCEPTION + ": " + (e.getMessage() != null ? e.getMessage() : ""))
91+
.setMessage(ExceptionUtils.getExceptionErrorString() + ": " + (e.getMessage() != null ? e.getMessage() : ""))
9292
.addDetails(Any.pack(DebugInfo.newBuilder()
9393
.setDetail(ExceptionUtils.getStackTrace(e))
9494
.build()))

src/main/java/io/numaproj/numaflow/sourcetransformer/TransformSupervisorActor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ private void handleFailure(Exception e) {
153153
// Build gRPC Status
154154
com.google.rpc.Status status = com.google.rpc.Status.newBuilder()
155155
.setCode(Code.INTERNAL.getNumber())
156-
.setMessage(ExceptionUtils.ERR_TRANSFORMER_EXCEPTION + ": " + (e.getMessage() != null ? e.getMessage() : ""))
156+
.setMessage(ExceptionUtils.getExceptionErrorString() + ": " + (e.getMessage() != null ? e.getMessage() : ""))
157157
.addDetails(Any.pack(DebugInfo.newBuilder()
158158
.setDetail(ExceptionUtils.getStackTrace(e))
159159
.build()))

src/test/java/io/numaproj/numaflow/batchmapper/ServerErrTest.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import io.grpc.testing.GrpcCleanupRule;
99
import io.numaproj.numaflow.map.v1.MapGrpc;
1010
import io.numaproj.numaflow.map.v1.MapOuterClass;
11+
import io.numaproj.numaflow.shared.ExceptionUtils;
1112
import org.junit.After;
1213
import org.junit.Before;
1314
import org.junit.Rule;
@@ -87,7 +88,7 @@ public void testErrorFromUDF() {
8788
outputStreamObserver.done.get();
8889
fail("Expected exception not thrown");
8990
} catch (InterruptedException | ExecutionException e) {
90-
String expectedSubstring = "UDF_EXECUTION_ERROR(batchmap)";
91+
String expectedSubstring = ExceptionUtils.getExceptionErrorString();
9192
String actualMessage = e.getMessage();
9293
assertNotNull("Error message should not be null", actualMessage);
9394
assertTrue("Expected substring '" + expectedSubstring + "' not found in error message: " + actualMessage,

src/test/java/io/numaproj/numaflow/mapper/ServerErrTest.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import io.grpc.testing.GrpcCleanupRule;
1515
import io.numaproj.numaflow.map.v1.MapGrpc;
1616
import io.numaproj.numaflow.map.v1.MapOuterClass;
17+
import io.numaproj.numaflow.shared.ExceptionUtils;
1718
import org.junit.After;
1819
import org.junit.Before;
1920
import org.junit.Rule;
@@ -127,7 +128,7 @@ public void testMapperFailure() {
127128
fail("Expected exception not thrown");
128129
} catch (Exception e) {
129130
assertEquals(
130-
"io.grpc.StatusRuntimeException: INTERNAL: UDF_EXECUTION_ERROR(map): unknown exception",
131+
"io.grpc.StatusRuntimeException: INTERNAL: " + ExceptionUtils.getExceptionErrorString() + ": unknown exception",
131132
e.getMessage());
132133
}
133134
}

src/test/java/io/numaproj/numaflow/servingstore/ServerErrTest.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import static org.junit.Assert.assertEquals;
44
import static org.junit.Assert.fail;
5+
import io.numaproj.numaflow.shared.ExceptionUtils;
56

67
public class ServerErrTest {
78

@@ -53,7 +54,7 @@ public void testServingStoreError() {
5354
.build());
5455
fail("Expected an exception to be thrown");
5556
} catch (Exception e) {
56-
assertEquals("INTERNAL: UDF_EXECUTION_ERROR(servingstore): unknown exception", e.getMessage());
57+
assertEquals("INTERNAL: " + ExceptionUtils.getExceptionErrorString() + ": unknown exception", e.getMessage());
5758
}
5859
}
5960

src/test/java/io/numaproj/numaflow/sourcetransformer/ServerErrTest.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import io.grpc.testing.GrpcCleanupRule;
88
import io.numaproj.numaflow.sourcetransformer.v1.SourceTransformGrpc;
99
import io.numaproj.numaflow.sourcetransformer.v1.Sourcetransformer;
10+
import io.numaproj.numaflow.shared.ExceptionUtils;
1011
import org.junit.After;
1112
import org.junit.Before;
1213
import org.junit.Rule;
@@ -88,7 +89,7 @@ public void testSourceTransformerFailure() {
8889
responseObserver.done.get();
8990
fail("Expected exception not thrown");
9091
} catch (Exception e) {
91-
String expectedSubstring = "UDF_EXECUTION_ERROR(transformer)";
92+
String expectedSubstring = ExceptionUtils.getExceptionErrorString();
9293
String actualMessage = e.getMessage();
9394
assertNotNull("Error message should not be null", actualMessage);
9495
assertTrue("Expected substring '" + expectedSubstring + "' not found in error message: " + actualMessage,

0 commit comments

Comments
 (0)