Skip to content

Commit

Permalink
return error if labels to be merged have no voxels
Browse files Browse the repository at this point in the history
  • Loading branch information
DocSavage committed Apr 10, 2024
1 parent 9163390 commit a039fad
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions datatype/labelmap/mutate.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ func (d *Data) MergeLabels(v dvid.VersionID, op labels.MergeOp, info dvid.ModInf
return
}
delta.MergedVoxels = mergeIdx.NumVoxels()
if delta.MergedVoxels == 0 {
err = fmt.Errorf("can't merge labels with no voxels: %s", op.Merged)
return
}

jsonBytes, _ := json.Marshal(msginfo)
if err := d.PublishKafkaMsg(jsonBytes); err != nil {
Expand Down
5 changes: 5 additions & 0 deletions datatype/labelmap/mutate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,11 @@ func TestMergeLabels(t *testing.T) {
if err := retrieved.equals(expected); err != nil {
t.Errorf("Merged label volume: %v\n", err)
}

// Make sure we can't merge the previously merged body again.
if err := testMerge.sendErr(t, uuid, "labels"); err == nil {
t.Fatalf("Expected error on re-merge of bodies, got none\n")
}
}

func TestSplitLabel(t *testing.T) {
Expand Down

0 comments on commit a039fad

Please sign in to comment.