Skip to content

Commit

Permalink
Merge pull request #152 from mimiro-io/fix/handle-missing-refs
Browse files Browse the repository at this point in the history
return storage error when entities contain nil refs
  • Loading branch information
rompetroll authored Aug 18, 2022
2 parents c305972 + 364259a commit 462df60
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions internal/server/dataset.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,8 @@ func (ds *Dataset) StoreEntitiesWithTransaction(entities []*Entity, txnTime int6
for i, v := range interfaceRefs {
refs[i] = v.(string)
}
case nil:
return newitems, fmt.Errorf("encountered nil ref, cannot store entity %v", e)
}

for _, ref := range refs {
Expand Down Expand Up @@ -503,8 +505,12 @@ func (ds *Dataset) StoreEntitiesWithTransaction(entities []*Entity, txnTime int6
// need to check if v is string or []string
refs, isArray := stringOrArrayValue.([]interface{})
if !isArray {
s := stringOrArrayValue.(interface{})
refs = []interface{}{s}
s, isSingle := stringOrArrayValue.(interface{})
if isSingle {
refs = []interface{}{s}
} else {
return newitems, fmt.Errorf("encountered nil reference, cannot store entity %v", e)
}
}

for _, ref := range refs {
Expand Down Expand Up @@ -579,6 +585,8 @@ func (ds *Dataset) StoreEntitiesWithTransaction(entities []*Entity, txnTime int6
for i, v := range interfaceRefs {
refs[i] = v.(string)
}
case nil:
return newitems, fmt.Errorf("encountered nil ref, cannot store entity %v", e)
}

for _, ref := range refs {
Expand Down

0 comments on commit 462df60

Please sign in to comment.