Skip to content

Commit

Permalink
Added error enrichment
Browse files Browse the repository at this point in the history
  • Loading branch information
wscalf committed Aug 14, 2024
1 parent 5e6ed40 commit d0ce8c6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 17 deletions.
9 changes: 5 additions & 4 deletions cmd/kessel-relations/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"flag"
"fmt"
"os"
"strings"

Expand Down Expand Up @@ -63,12 +64,12 @@ func main() {
defer c.Close()

if err := c.Load(); err != nil {
panic(err)
panic(fmt.Errorf("error loading configuration: %w", err))
}

var bc conf.Bootstrap
if err := c.Scan(&bc); err != nil {
panic(err)
panic(fmt.Errorf("error reading bootstrap config from configuration: %w", err))
}

//preshared, err := c.Value("PRESHARED").String()
Expand All @@ -81,13 +82,13 @@ func main() {

app, cleanup, err := wireApp(bc.Server, bc.Data, createLogger(bc.Server))
if err != nil {
panic(err)
panic(fmt.Errorf("error initializing application (via wire): %w", err))
}
defer cleanup()

// start and wait for stop signal
if err := app.Run(); err != nil {
panic(err)
panic(fmt.Errorf("fatal error during application execution: %w", err))
}
}

Expand Down
11 changes: 1 addition & 10 deletions internal/data/spicedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func NewSpiceDbRepository(c *conf.Data, logger log.Logger) (*SpiceDbRepository,
token, err = readToken(c.SpiceDb.TokenFile)
if err != nil {
log.NewHelper(logger).Error(err)
return nil, nil, err
return nil, nil, fmt.Errorf("error creating spicedb client: error loading token file: %w", err)
}
}
if token == "" {
Expand Down Expand Up @@ -442,19 +442,10 @@ func createSpiceDbRelationship(relationship *apiV1beta1.Relationship) *v1.Relati
}

func readToken(file string) (string, error) {
isFileExist := checkFileExists(file)
if !isFileExist {
return file, errors.New("file doesn't exist")
}
bytes, err := os.ReadFile(file)
if err != nil {
return "", err
}

return string(bytes), nil
}

func checkFileExists(filePath string) bool {
_, err := os.Stat(filePath)
return !errors.Is(err, os.ErrNotExist)
}
6 changes: 3 additions & 3 deletions internal/service/lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,20 +84,20 @@ func (s *LookupService) LookupResources(req *pb.LookupResourcesRequest, conn pb.
res, errs, err := s.resourcesUsecase.Get(ctx, req)

if err != nil {
return err
return fmt.Errorf("failed to retrieve resources: %w", err)
}
for re := range res {
err = conn.Send(&pb.LookupResourcesResponse{
Resource: re.Resource,
Pagination: &pb.ResponsePagination{ContinuationToken: string(re.Continuation)},
})
if err != nil {
return err
return fmt.Errorf("error sending retrieved resource to the client: %w", err)
}
}
err, ok := <-errs
if ok {
return err
return fmt.Errorf("error received while streaming subjects from Zanzibar backend: %w", err)
}

return nil
Expand Down

0 comments on commit d0ce8c6

Please sign in to comment.