mirror of
https://github.com/coder/coder.git
synced 2025-07-03 16:13:58 +00:00
test: Handle Filter flake with ctx errors (#7119)
* test: Handle Fitler flake with ctx errors * Add unit test to check filter for proper error * Correctly return category of errors
This commit is contained in:
@ -1,11 +1,14 @@
|
||||
package rbac
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
|
||||
"github.com/open-policy-agent/opa/rego"
|
||||
"github.com/open-policy-agent/opa/topdown"
|
||||
"golang.org/x/xerrors"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -97,3 +100,17 @@ func (*UnauthorizedError) As(target interface{}) bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// correctCancelError will return the correct error for a canceled context. This
|
||||
// is because rego changes a canceled context to a topdown.CancelErr. This error
|
||||
// is not helpful if the code is "canceled". To make the error conform with the
|
||||
// rest of our canceled errors, we will convert the error to a context.Canceled
|
||||
// error. No good information is lost, as the topdown.CancelErr provides the
|
||||
// location of the query that was canceled, which does not matter.
|
||||
func correctCancelError(err error) error {
|
||||
e := new(topdown.Error)
|
||||
if xerrors.As(err, &e) || e.Code == topdown.CancelErr {
|
||||
return context.Canceled
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
Reference in New Issue
Block a user