Skip to content

Commit

Permalink
🐛 handle OOM errors and fix default location (#661)
Browse files Browse the repository at this point in the history
Signed-off-by: Shawn Hurley <[email protected]>
  • Loading branch information
shawn-hurley authored Jul 17, 2024
1 parent dc66315 commit 00f45aa
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions jsonrpc2/jsonrpc2.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions jsonrpc2/rpcerr.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit 00f45aa

Please sign in to comment.