From 1765ae8db4d0d5e615fc3b55275e563dd5a1c687 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20M=C3=BCller?= Date: Fri, 9 Apr 2021 09:12:34 +0200 Subject: [PATCH] Make local file connector more error tolerant (#1625) --- changelog/unreleased/fix-mentix-local-file.md | 5 +++++ pkg/mentix/connectors/localfile.go | 19 +++++++++---------- 2 files changed, 14 insertions(+), 10 deletions(-) create mode 100644 changelog/unreleased/fix-mentix-local-file.md diff --git a/changelog/unreleased/fix-mentix-local-file.md b/changelog/unreleased/fix-mentix-local-file.md new file mode 100644 index 0000000000..1c37953958 --- /dev/null +++ b/changelog/unreleased/fix-mentix-local-file.md @@ -0,0 +1,5 @@ +Bugfix: Make local file connector more error tolerant + +The local file connector caused Reva to throw an exception if the local file for storing site data couldn't be loaded. This PR changes this behavior so that only a warning is logged. + +https://github.com/cs3org/reva/pull/1625 diff --git a/pkg/mentix/connectors/localfile.go b/pkg/mentix/connectors/localfile.go index 6b83aab568..ed521353fc 100755 --- a/pkg/mentix/connectors/localfile.go +++ b/pkg/mentix/connectors/localfile.go @@ -64,22 +64,21 @@ func (connector *LocalFileConnector) Activate(conf *config.Configuration, log *z // RetrieveMeshData fetches new mesh data. func (connector *LocalFileConnector) RetrieveMeshData() (*meshdata.MeshData, error) { - meshData := &meshdata.MeshData{} - jsonData, err := ioutil.ReadFile(connector.filePath) if err != nil { - return nil, fmt.Errorf("unable to read file '%v': %v", connector.filePath, err) + connector.log.Warn().Err(err).Msgf("unable to read file '%v'", connector.filePath) + return &meshdata.MeshData{}, nil } - if err := json.Unmarshal(jsonData, &meshData.Sites); err != nil { - return nil, fmt.Errorf("invalid file '%v': %v", connector.filePath, err) + meshData := &meshdata.MeshData{} + if err := json.Unmarshal(jsonData, &meshData.Sites); err == nil { + // Enforce site types + connector.setSiteTypes(meshData) + meshData.InferMissingData() + } else { + connector.log.Warn().Err(err).Msgf("invalid file '%v'", connector.filePath) } - // Enforce site types - connector.setSiteTypes(meshData) - - meshData.InferMissingData() - return meshData, nil }