From 00f45aaa3d24283012ea72bd9438c2d967680c82 Mon Sep 17 00:00:00 2001 From: Shawn Hurley Date: Wed, 17 Jul 2024 15:25:41 -0400 Subject: [PATCH] :bug: handle OOM errors and fix default location (#661) Signed-off-by: Shawn Hurley --- .../pkg/java_external_provider/provider.go | 2 +- jsonrpc2/jsonrpc2.go | 3 +++ jsonrpc2/rpcerr.go | 6 ++++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/external-providers/java-external-provider/pkg/java_external_provider/provider.go b/external-providers/java-external-provider/pkg/java_external_provider/provider.go index 5d7afe33..f37880d3 100644 --- a/external-providers/java-external-provider/pkg/java_external_provider/provider.go +++ b/external-providers/java-external-provider/pkg/java_external_provider/provider.go @@ -46,7 +46,7 @@ const ( // Rule Location to location that the bundle understands var locationToCode = map[string]int{ //Type is the default. - "": 10, + "": 0, "inheritance": 1, "method_call": 2, "constructor_call": 3, diff --git a/jsonrpc2/jsonrpc2.go b/jsonrpc2/jsonrpc2.go index 23c6a86c..e23e773c 100644 --- a/jsonrpc2/jsonrpc2.go +++ b/jsonrpc2/jsonrpc2.go @@ -159,6 +159,9 @@ func (c *Conn) Call(ctx context.Context, method string, params, result interface } // is it an error response? if response.Error != nil { + if IsOOMError(response.Error) { + return fmt.Errorf("out of memory error, query is too broad or we need more resources") + } return response.Error } if result == nil || response.Result == nil { diff --git a/jsonrpc2/rpcerr.go b/jsonrpc2/rpcerr.go index 3514cb03..96df3245 100644 --- a/jsonrpc2/rpcerr.go +++ b/jsonrpc2/rpcerr.go @@ -1,13 +1,19 @@ package jsonrpc2 import ( + "fmt" "strings" ) var errFileClosed = "file already closed" var errBrokenPipe = "broken pipe" +var oomError = "java.lang.OutOfMemoryError" func IsRPCClosed(err error) bool { var errMsg = err.Error() return strings.HasSuffix(errMsg, errFileClosed) || strings.HasSuffix(errMsg, errBrokenPipe) } + +func IsOOMError(err *Error) bool { + return strings.Contains(fmt.Sprintf("%s", err.Data), oomError) +}