-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix crash due to mismatch number of columns and values in a row (#349)
* Fix crash due to mismatch number of columns and values in a row * Fix lint error * Rename field
- Loading branch information
1 parent
4ed1400
commit ca54bfd
Showing
12 changed files
with
130 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
engines/router/missionctl/server/upi/interceptors/recoverer.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package interceptors | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"google.golang.org/grpc" | ||
) | ||
|
||
// PanicRecoveryInterceptor interceptor to recover after facing panic | ||
func PanicRecoveryInterceptor() grpc.UnaryServerInterceptor { | ||
return func(ctx context.Context, | ||
req interface{}, | ||
info *grpc.UnaryServerInfo, | ||
handler grpc.UnaryHandler) (resp interface{}, err error) { | ||
defer func(ctx context.Context) { | ||
if r := recover(); r != nil { | ||
if e, ok := r.(error); ok { | ||
err = e | ||
} else { | ||
err = fmt.Errorf("panic: %s", r) | ||
} | ||
} | ||
}(ctx) | ||
|
||
resp, err = handler(ctx, req) | ||
return resp, err | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
engines/router/missionctl/server/upi/interceptors/recoverer_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package interceptors | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
upiv1 "github.com/caraml-dev/universal-prediction-interface/gen/go/grpc/caraml/upi/v1" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestPanicRecovery(t *testing.T) { | ||
t.Run("Test panic recovery", func(t *testing.T) { | ||
panicIntercep := PanicRecoveryInterceptor() | ||
_, err := panicIntercep( | ||
context.Background(), | ||
&upiv1.PredictValuesRequest{}, | ||
nil, | ||
func(ctx context.Context, req interface{}) (interface{}, error) { | ||
panic("something wrong") | ||
}) | ||
assert.Equal(t, "panic: something wrong", err.Error()) | ||
}) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters