Skip to content

Commit 8270393

Browse files
authored
Fix the response for check shared on JSON errors (#2869)
Some old io.cozy.shared documents have a JSON with more than 10000 levels of nesting. With go 1.15+, these documents cannot be parsed as JSON. This commit makes the check shared to return a correct response.
1 parent f6264de commit 8270393

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

model/sharing/shared.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,10 +475,11 @@ func extractDocReferenceFromID(id string) *couchdb.DocReference {
475475
// revision tree for inconsistencies.
476476
func CheckShared(inst *instance.Instance) ([]*CheckSharedError, error) {
477477
checks := []*CheckSharedError{}
478-
err := couchdb.ForeachDocs(inst, consts.Shared, func(_ string, data json.RawMessage) error {
478+
err := couchdb.ForeachDocs(inst, consts.Shared, func(id string, data json.RawMessage) error {
479479
s := &SharedRef{}
480480
if err := json.Unmarshal(data, s); err != nil {
481-
return err
481+
checks = append(checks, &CheckSharedError{Type: "invalid_json", ID: id})
482+
return nil
482483
}
483484
if check := s.Revisions.check(); check != nil {
484485
check.ID = s.SID

web/instances/checks.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,11 @@ func checkShared(c echo.Context) error {
216216
{"type": "no_database", "error": err.Error()},
217217
})
218218
}
219+
if _, ok := err.(*json.SyntaxError); ok {
220+
return c.JSON(http.StatusOK, []map[string]interface{}{
221+
{"type": "invalid_json", "error": err.Error()},
222+
})
223+
}
219224
return wrapError(err)
220225
}
221226
return c.JSON(http.StatusOK, results)

0 commit comments

Comments
 (0)