Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix handling of async query errors #47

Merged
merged 2 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions policy/policy_handler/async.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import (
"context"
b64 "encoding/base64"
"fmt"

"github.com/atomist-skills/go-skill/policy/goals"
"github.com/atomist-skills/go-skill/policy/types"

"github.com/atomist-skills/go-skill"
"github.com/atomist-skills/go-skill/policy/data"
Expand Down Expand Up @@ -72,6 +74,9 @@ func buildAsyncDataSources(multipleQuerySupport bool) dataSourceProvider {
}

metaEdn, err := b64.StdEncoding.DecodeString(req.Event.Context.AsyncQueryResult.Metadata)
if err != nil {
return nil, fmt.Errorf("failed to decode metadata: %w", err)
}

var metadata data.AsyncResultMetadata
err = edn.Unmarshal(metaEdn, &metadata)
Expand All @@ -84,6 +89,13 @@ func buildAsyncDataSources(multipleQuerySupport bool) dataSourceProvider {
if err != nil {
return nil, fmt.Errorf("failed to unmarshal async query result: %w", err)
}
if len(queryResponse.Errors) > 0 {
errorMessage := queryResponse.Errors[0].Message
if errorMessage == "An unexpected error has occurred" {
return nil, fmt.Errorf("async query contained error: %s", errorMessage).(types.RetryableExecutionError)
}
return nil, fmt.Errorf("async query contained error: %s", errorMessage)
}
Comment on lines +92 to +98
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm good with this being here, but you should also then remove the error handling in gql_async.go

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good shout.

metadata.AsyncQueryResults[metadata.InFlightQueryName] = queryResponse

return []data.DataSource{
Expand Down
5 changes: 3 additions & 2 deletions policy/policy_handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/atomist-skills/go-skill/policy/data"
"github.com/atomist-skills/go-skill/policy/goals"
"github.com/atomist-skills/go-skill/policy/storage"
"github.com/atomist-skills/go-skill/policy/types"
"github.com/atomist-skills/go-skill/util"
"olympos.io/encoding/edn"
)
Expand Down Expand Up @@ -94,8 +95,8 @@ func (h EventHandler) handle(ctx context.Context, req skill.RequestContext) skil
for _, provider := range h.dataSourceProviders {
ds, err := provider(ctx, req, *evaluationMetadata)
if err != nil {
if err.Error() == "An unexpected error has occurred" {
return skill.NewRetryableStatus(fmt.Sprintf("Failed to create data source [%s]", err.Error()))
if retryableError, ok := err.(types.RetryableExecutionError); ok {
return skill.NewRetryableStatus(fmt.Sprintf("Failed to create data source [%s]", retryableError.Error()))
}
return skill.NewFailedStatus(fmt.Sprintf("failed to create data source [%s]", err.Error()))
}
Expand Down
9 changes: 9 additions & 0 deletions policy/types/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package types

import "fmt"

type RetryableExecutionError string

func (e RetryableExecutionError) Error() string {
return fmt.Sprint(string(e))
}
Loading