@@ -17,6 +17,7 @@ import (
1717
1818 "github.com/CircleCI-Public/circleci-cli/api/graphql"
1919 "github.com/CircleCI-Public/circleci-cli/api/rest"
20+ "github.com/CircleCI-Public/circleci-cli/errs"
2021 "github.com/CircleCI-Public/circleci-cli/references"
2122 "github.com/CircleCI-Public/circleci-cli/settings"
2223)
@@ -54,6 +55,10 @@ func (errs GQLErrorsCollection) Error() string {
5455 return strings .Join (messages , "\n " )
5556}
5657
58+ func wrapGQLErrors (gqlErrors GQLErrorsCollection ) error {
59+ return errs .CheckAuthRequired (gqlErrors )
60+ }
61+
5762// GQLResponseError is a mapping of the data returned by the GraphQL server of key-value pairs.
5863// Typically used with the structure "Message: string", but other response errors provide additional fields.
5964type GQLResponseError struct {
@@ -543,7 +548,7 @@ func OrbImportVersion(cl *graphql.Client, orbSrc string, orbID string, orbVersio
543548 }
544549
545550 if len (response .ImportOrbVersion .Errors ) > 0 {
546- return nil , response .ImportOrbVersion .Errors
551+ return nil , wrapGQLErrors ( response .ImportOrbVersion .Errors )
547552 }
548553
549554 return & response .ImportOrbVersion .Orb , nil
@@ -590,7 +595,7 @@ func OrbPublishByName(cl *graphql.Client, configPath, orbName, namespaceName, or
590595 }
591596
592597 if len (response .PublishOrb .Errors ) > 0 {
593- return nil , response .PublishOrb .Errors
598+ return nil , wrapGQLErrors ( response .PublishOrb .Errors )
594599 }
595600
596601 return & response .PublishOrb .Orb , nil
@@ -663,7 +668,7 @@ func OrbID(cl *graphql.Client, namespace string, orb string) (*OrbIDResponse, er
663668 return nil , namespaceNotFound (namespace )
664669 }
665670
666- return nil , fmt . Errorf ("the '%s' orb does not exist in the '%s' namespace. Did you misspell the namespace or the orb name?" , orb , namespace )
671+ return nil , errs . NotFoundf ("the '%s' orb does not exist in the '%s' namespace. Did you misspell the namespace or the orb name?" , orb , namespace )
667672}
668673
669674// CreateImportedNamespace creates an imported namespace with the provided name. An imported namespace
@@ -697,7 +702,7 @@ func CreateImportedNamespace(cl *graphql.Client, name string) (*ImportNamespaceR
697702 }
698703
699704 if len (response .ImportNamespace .Errors ) > 0 {
700- return nil , response .ImportNamespace .Errors
705+ return nil , wrapGQLErrors ( response .ImportNamespace .Errors )
701706 }
702707
703708 return & response , nil
@@ -731,7 +736,7 @@ func CreateNamespaceWithOwnerID(cl *graphql.Client, name string, ownerID string)
731736 err := cl .Run (request , & response )
732737
733738 if len (response .CreateNamespace .Errors ) > 0 {
734- return nil , response .CreateNamespace .Errors
739+ return nil , wrapGQLErrors ( response .CreateNamespace .Errors )
735740 }
736741
737742 if err != nil {
@@ -828,7 +833,7 @@ mutation($name: String!) {
828833 }
829834
830835 if len (response .DeleteNamespaceAlias .Errors ) > 0 {
831- return response .DeleteNamespaceAlias .Errors
836+ return wrapGQLErrors ( response .DeleteNamespaceAlias .Errors )
832837 }
833838
834839 if ! response .DeleteNamespaceAlias .Deleted {
@@ -866,7 +871,7 @@ mutation($id: UUID!) {
866871 }
867872
868873 if len (response .DeleteNamespace .Errors ) > 0 {
869- return response .DeleteNamespace .Errors
874+ return wrapGQLErrors ( response .DeleteNamespace .Errors )
870875 }
871876
872877 if ! response .DeleteNamespace .Deleted {
@@ -977,7 +982,7 @@ func renameNamespaceWithNsID(cl *graphql.Client, id, newName string) (*RenameNam
977982 err := cl .Run (request , & response )
978983
979984 if len (response .RenameNamespace .Errors ) > 0 {
980- return nil , response .RenameNamespace .Errors
985+ return nil , wrapGQLErrors ( response .RenameNamespace .Errors )
981986 }
982987
983988 if err != nil {
@@ -1024,7 +1029,7 @@ func createOrbWithNsID(cl *graphql.Client, name string, namespaceID string, isPr
10241029 err := cl .Run (request , & response )
10251030
10261031 if len (response .CreateOrb .Errors ) > 0 {
1027- return nil , response .CreateOrb .Errors
1032+ return nil , wrapGQLErrors ( response .CreateOrb .Errors )
10281033 }
10291034
10301035 if err != nil {
@@ -1080,7 +1085,7 @@ func CreateImportedOrb(cl *graphql.Client, namespace string, name string) (*Impo
10801085 }
10811086
10821087 if len (response .ImportOrb .Errors ) > 0 {
1083- return nil , response .ImportOrb .Errors
1088+ return nil , wrapGQLErrors ( response .ImportOrb .Errors )
10841089 }
10851090
10861091 return & response , nil
@@ -1201,7 +1206,7 @@ func OrbPromoteByName(cl *graphql.Client, namespaceName, orbName, label, segment
12011206 err = cl .Run (request , & response )
12021207
12031208 if len (response .PromoteOrb .Errors ) > 0 {
1204- return nil , response .PromoteOrb .Errors
1209+ return nil , wrapGQLErrors ( response .PromoteOrb .Errors )
12051210 }
12061211
12071212 if err != nil {
@@ -1244,7 +1249,7 @@ mutation($orbId: UUID!, $list: Boolean!) {
12441249 err = cl .Run (request , & response )
12451250
12461251 if len (response .SetOrbListStatus .Errors ) > 0 {
1247- return nil , response .SetOrbListStatus .Errors
1252+ return nil , wrapGQLErrors ( response .SetOrbListStatus .Errors )
12481253 }
12491254
12501255 if err != nil {
@@ -1298,7 +1303,7 @@ func OrbSource(cl *graphql.Client, orbRef string) (string, error) {
12981303 }
12991304
13001305 if response .OrbVersion .ID == "" {
1301- return "" , fmt . Errorf ( "no Orb '%s' was found; please check that the Orb reference is correct" , orbRef )
1306+ return "" , & ErrOrbVersionNotExists { OrbRef : orbRef }
13021307 }
13031308
13041309 return response .OrbVersion .Source , nil
@@ -1315,6 +1320,8 @@ func (e *ErrOrbVersionNotExists) Error() string {
13151320 return fmt .Sprintf ("no Orb '%s' was found; please check that the Orb reference is correct" , e .OrbRef )
13161321}
13171322
1323+ func (e * ErrOrbVersionNotExists ) Is (target error ) bool { return target == errs .ErrNotFound }
1324+
13181325// OrbInfo gets the meta-data of an orb
13191326func OrbInfo (cl * graphql.Client , orbRef string ) (* OrbVersion , error ) {
13201327 if err := references .IsOrbRefWithOptionalVersion (orbRef ); err != nil {
@@ -1714,7 +1721,7 @@ func AddOrRemoveOrbCategorization(cl *graphql.Client, namespace string, orb stri
17141721 responseData := response [mutationName ]
17151722
17161723 if len (responseData .Errors ) > 0 {
1717- return & responseData .Errors
1724+ return wrapGQLErrors ( responseData .Errors )
17181725 }
17191726
17201727 if err != nil {
0 commit comments