From 90b7886142886acfb1a8bc7f7c5f934e5d7ec973 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Wed, 4 Aug 2021 15:34:53 +0200 Subject: [PATCH] Fix unmarshalling GraphQL error type The "path" field of a GraphQL error object contains a mix of strings and numbers and cannot be deserialized into `[]string`. Fortunately, we don't need to rely on the "path" field and instead have the final error message be constructed by aggregating human-readable "message" fields. --- api/client.go | 2 +- pkg/cmd/secret/set/http.go | 12 +----------- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/api/client.go b/api/client.go index 0ff48032a..196c65692 100644 --- a/api/client.go +++ b/api/client.go @@ -123,8 +123,8 @@ type graphQLResponse struct { // GraphQLError is a single error returned in a GraphQL response type GraphQLError struct { Type string - Path []string Message string + // Path []interface // mixed strings and numbers } // GraphQLErrorResponse contains errors returned in a GraphQL response diff --git a/pkg/cmd/secret/set/http.go b/pkg/cmd/secret/set/http.go index 90f09b913..b0626e92e 100644 --- a/pkg/cmd/secret/set/http.go +++ b/pkg/cmd/secret/set/http.go @@ -130,17 +130,7 @@ func mapRepoNameToID(client *api.Client, host, orgName string, repositoryNames [ DatabaseID int `json:"databaseId"` }) - err := client.GraphQL(host, query, nil, &graphqlResult) - - gqlErr, isGqlErr := err.(*api.GraphQLErrorResponse) - if isGqlErr { - for _, ge := range gqlErr.Errors { - if ge.Type == "NOT_FOUND" { - return nil, fmt.Errorf("could not find %s/%s", orgName, ge.Path[0]) - } - } - } - if err != nil { + if err := client.GraphQL(host, query, nil, &graphqlResult); err != nil { return nil, fmt.Errorf("failed to look up repositories: %w", err) }