isolate the actual error from this query

I couldn't the exact error, so this is the best approximation i could come up with.
This commit is contained in:
ryanfkeepers 2024-02-13 17:23:08 -07:00
parent 368a246596
commit 3ea2e4734d
3 changed files with 32 additions and 6 deletions

View File

@ -2,6 +2,7 @@ package exchange
import ( import (
"errors" "errors"
"net/http"
"slices" "slices"
"github.com/alcionai/clues" "github.com/alcionai/clues"
@ -60,13 +61,21 @@ func (h eventBackupHandler) NewContainerCache(
} }
} }
// todo: this could be further improved buy specifying the call source and matching that
// with the expected error. Might be necessary if we use this for more than one error.
// But since we only call this in a single place at this time, that additional guard isn't
// built into the func.
func (h eventBackupHandler) CanSkipItemFailure( func (h eventBackupHandler) CanSkipItemFailure(
err error, err error,
resourceID, itemID string, resourceID, itemID string,
opts control.Options, opts control.Options,
) (fault.SkipCause, bool) { ) (fault.SkipCause, bool) {
// yes, this is intentionally a todo. I'll get back to it. if err == nil {
if !errors.Is(err, clues.New("todo fix me")) { return "", false
}
if !errors.Is(err, graph.ErrServiceUnavailableEmptyResp) &&
!clues.HasLabel(err, graph.LabelStatus(http.StatusServiceUnavailable)) {
return "", false return "", false
} }

View File

@ -1,6 +1,7 @@
package exchange package exchange
import ( import (
"net/http"
"testing" "testing"
"github.com/alcionai/clues" "github.com/alcionai/clues"
@ -12,6 +13,7 @@ import (
"github.com/alcionai/corso/src/pkg/control" "github.com/alcionai/corso/src/pkg/control"
"github.com/alcionai/corso/src/pkg/fault" "github.com/alcionai/corso/src/pkg/fault"
"github.com/alcionai/corso/src/pkg/services/m365/api" "github.com/alcionai/corso/src/pkg/services/m365/api"
"github.com/alcionai/corso/src/pkg/services/m365/api/graph"
) )
type EventsBackupHandlerUnitSuite struct { type EventsBackupHandlerUnitSuite struct {
@ -61,7 +63,7 @@ func (suite *EventsBackupHandlerUnitSuite) TestHandler_CanSkipItemFailure() {
}, },
{ {
name: "non-matching resource", name: "non-matching resource",
err: clues.New("fix me I'm wrong"), err: graph.ErrServiceUnavailableEmptyResp,
opts: control.Options{ opts: control.Options{
SkipTheseEventsOnInstance503: map[string][]string{ SkipTheseEventsOnInstance503: map[string][]string{
"foo": {"bar", "baz"}, "foo": {"bar", "baz"},
@ -71,17 +73,31 @@ func (suite *EventsBackupHandlerUnitSuite) TestHandler_CanSkipItemFailure() {
}, },
{ {
name: "non-matching item", name: "non-matching item",
err: clues.New("fix me I'm wrong"), err: graph.ErrServiceUnavailableEmptyResp,
opts: control.Options{ opts: control.Options{
SkipTheseEventsOnInstance503: map[string][]string{ SkipTheseEventsOnInstance503: map[string][]string{
resourceID: {"bar", "baz"}, resourceID: {"bar", "baz"},
}, },
}, },
expect: assert.False, expect: assert.False,
// the item won't match, but we still return this as the cause
expectCause: fault.SkipKnownEventInstance503s,
},
{
name: "match on instance 503 empty resp",
err: graph.ErrServiceUnavailableEmptyResp,
opts: control.Options{
SkipTheseEventsOnInstance503: map[string][]string{
resourceID: {"bar", itemID},
},
},
expect: assert.True,
expectCause: fault.SkipKnownEventInstance503s,
}, },
{ {
name: "match on instance 503", name: "match on instance 503",
err: clues.New("fix me I'm wrong"), err: clues.New("arbitrary error").
Label(graph.LabelStatus(http.StatusServiceUnavailable)),
opts: control.Options{ opts: control.Options{
SkipTheseEventsOnInstance503: map[string][]string{ SkipTheseEventsOnInstance503: map[string][]string{
resourceID: {"bar", itemID}, resourceID: {"bar", itemID},

View File

@ -156,7 +156,8 @@ func stackWithCoreErr(ctx context.Context, err error, traceDepth int) error {
labels = append(labels, core.LabelRootCauseUnknown) labels = append(labels, core.LabelRootCauseUnknown)
} }
stacked := stackWithDepth(ctx, err, 1+traceDepth) stacked := stackWithDepth(ctx, err, 1+traceDepth).
Label(LabelStatus(ode.Resp.StatusCode))
// labeling here because we want the context from stackWithDepth first // labeling here because we want the context from stackWithDepth first
for _, label := range labels { for _, label := range labels {