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 (
"errors"
"net/http"
"slices"
"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(
err error,
resourceID, itemID string,
opts control.Options,
) (fault.SkipCause, bool) {
// yes, this is intentionally a todo. I'll get back to it.
if !errors.Is(err, clues.New("todo fix me")) {
if err == nil {
return "", false
}
if !errors.Is(err, graph.ErrServiceUnavailableEmptyResp) &&
!clues.HasLabel(err, graph.LabelStatus(http.StatusServiceUnavailable)) {
return "", false
}

View File

@ -1,6 +1,7 @@
package exchange
import (
"net/http"
"testing"
"github.com/alcionai/clues"
@ -12,6 +13,7 @@ import (
"github.com/alcionai/corso/src/pkg/control"
"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/graph"
)
type EventsBackupHandlerUnitSuite struct {
@ -61,7 +63,7 @@ func (suite *EventsBackupHandlerUnitSuite) TestHandler_CanSkipItemFailure() {
},
{
name: "non-matching resource",
err: clues.New("fix me I'm wrong"),
err: graph.ErrServiceUnavailableEmptyResp,
opts: control.Options{
SkipTheseEventsOnInstance503: map[string][]string{
"foo": {"bar", "baz"},
@ -71,17 +73,31 @@ func (suite *EventsBackupHandlerUnitSuite) TestHandler_CanSkipItemFailure() {
},
{
name: "non-matching item",
err: clues.New("fix me I'm wrong"),
err: graph.ErrServiceUnavailableEmptyResp,
opts: control.Options{
SkipTheseEventsOnInstance503: map[string][]string{
resourceID: {"bar", "baz"},
},
},
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",
err: clues.New("fix me I'm wrong"),
err: clues.New("arbitrary error").
Label(graph.LabelStatus(http.StatusServiceUnavailable)),
opts: control.Options{
SkipTheseEventsOnInstance503: map[string][]string{
resourceID: {"bar", itemID},

View File

@ -156,7 +156,8 @@ func stackWithCoreErr(ctx context.Context, err error, traceDepth int) error {
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
for _, label := range labels {