Skip to content

Commit

Permalink
Add RepositoryNotFound and ViewNotFound responses to Get() calls
Browse files Browse the repository at this point in the history
  • Loading branch information
SaaldjorMike committed Aug 13, 2024
1 parent 70a7e6f commit 9609a91
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
16 changes: 16 additions & 0 deletions api/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
type EntityType string

const (
EntityTypeRepository EntityType = "repository"
EntityTypeView EntityType = "view"
EntityTypeIngestToken EntityType = "ingest-token"
EntityTypeParser EntityType = "parser"
EntityTypeAction EntityType = "action"
Expand Down Expand Up @@ -37,6 +39,20 @@ func (e EntityNotFound) Error() string {
return fmt.Sprintf("%s %q not found", e.entityType.String(), e.key)
}

func RepositoryNotFound(name string) error {
return EntityNotFound{
entityType: EntityTypeRepository,
key: name,
}
}

func ViewNotFound(name string) error {
return EntityNotFound{
entityType: EntityTypeView,
key: name,
}
}

func IngestTokenNotFound(name string) error {
return EntityNotFound{
entityType: EntityTypeIngestToken,
Expand Down
3 changes: 1 addition & 2 deletions api/repositories.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ func (r *Repositories) Get(name string) (Repository, error) {
err := r.client.Query(&query, variables)

if err != nil {
// The graphql error message is vague if the repo already exists, so add a hint.
return query.Repository, fmt.Errorf("%w. Does the repo already exist?", err)
return query.Repository, fmt.Errorf("repository not found, does the repo already exist? err=%w, details=%s", RepositoryNotFound(name), err)
}

return query.Repository, nil
Expand Down
3 changes: 2 additions & 1 deletion api/views.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package api

import (
"fmt"
"sort"
"strings"

Expand Down Expand Up @@ -48,7 +49,7 @@ func (c *Views) Get(name string) (*View, error) {

err := c.client.Query(&query, variables)
if err != nil {
return nil, err
return nil, fmt.Errorf("view not found, does the view already exist? err=%w, details=%s", ViewNotFound(name), err)
}

connections := make([]ViewConnection, len(query.Result.ViewInfo.Connections))
Expand Down

0 comments on commit 9609a91

Please sign in to comment.