Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make local file connector more error tolerant #1625

Merged
merged 14 commits into from
Apr 9, 2021
Merged
5 changes: 5 additions & 0 deletions changelog/unreleased/fix-mentix-local-file.md
Original file line number Diff line number Diff line change
@@ -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
19 changes: 9 additions & 10 deletions pkg/mentix/connectors/localfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down