mirror of
https://github.com/open-policy-agent/opa.git
synced 2026-08-13 03:42:35 -06:00
server: Wrap decision log error messages
Previously the server didn't wrap the error messages which made it hard to determine the source of internal errors coming back from OPA when deployed with a custom decision logger. Fixes #1367 Signed-off-by: Torin Sandall <torinsandall@gmail.com>
This commit is contained in:
+1
-1
@@ -2400,7 +2400,7 @@ func (l decisionLogger) Log(ctx context.Context, txn storage.Transaction, decisi
|
||||
|
||||
if l.logger != nil {
|
||||
if err := l.logger(ctx, info); err != nil {
|
||||
return err
|
||||
return errors.Wrap(err, "decision_logs")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2780,6 +2780,22 @@ func TestDecisionLogging(t *testing.T) {
|
||||
|
||||
}
|
||||
|
||||
func TestDecisionLogErrorMessage(t *testing.T) {
|
||||
|
||||
f := newFixture(t)
|
||||
|
||||
f.server.WithDecisionLoggerWithErr(func(context.Context, *Info) error {
|
||||
return fmt.Errorf("xxx")
|
||||
})
|
||||
|
||||
if err := f.v1(http.MethodPost, "/data", "", 500, `{
|
||||
"code": "internal_error",
|
||||
"message": "decision_logs: xxx"
|
||||
}`); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWatchParams(t *testing.T) {
|
||||
f := newFixture(t)
|
||||
r1 := newMockConn()
|
||||
|
||||
Reference in New Issue
Block a user