go-micro errors on bundles (OCIS-363)

This commit is contained in:
A.Unger
2020-08-19 11:29:53 +02:00
committed by Benedikt Kulmann
parent dedcbd0412
commit 5f07c992da
2 changed files with 5 additions and 4 deletions

View File

@@ -23,7 +23,7 @@ func (s Store) ListBundles(bundleType proto.Bundle_Type) ([]*proto.Bundle, error
bundlesFolder := s.buildFolderPathForBundles(false)
bundleFiles, err := ioutil.ReadDir(bundlesFolder)
if err != nil {
return []*proto.Bundle{}, nil
return []*proto.Bundle{}, merrors.FromError(err)
}
records := make([]*proto.Bundle, 0, len(bundleFiles))

View File

@@ -5,6 +5,7 @@ import (
"github.com/golang/protobuf/jsonpb"
"github.com/golang/protobuf/proto"
merrors "github.com/micro/go-micro/v2/errors"
)
// Unmarshal file into record
@@ -12,7 +13,7 @@ func (s Store) parseRecordFromFile(record proto.Message, filePath string) error
file, err := os.Open(filePath)
if err != nil {
s.Logger.Err(err).Msgf("error reading file %v: file not found", filePath)
return err
return merrors.FromError(err)
}
defer file.Close()
@@ -29,14 +30,14 @@ func (s Store) writeRecordToFile(record proto.Message, filePath string) error {
file, err := os.Create(filePath)
if err != nil {
s.Logger.Err(err).Msgf("error writing file %v: opening failed", filePath)
return err
return merrors.FromError(err)
}
defer file.Close()
encoder := jsonpb.Marshaler{}
if err = encoder.Marshal(file, record); err != nil {
s.Logger.Err(err).Msgf("error writing file %v: marshalling failed", filePath)
return err
return merrors.FromError(err)
}
return nil