Skip to content

Commit 6b3ede1

Browse files
committed
test fix, KeyError
1 parent 4fbbecf commit 6b3ede1

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ Listing news on any major breaking changes in DFG. For regular changes, see int
22

33
# v0.20
44

5+
- Throw `KeyError` if `getBlobEntry` is not found, previously was `ErrorException`.
56
- Change return type on `addData!` convenience wrappers to only return new `BlobEntry`.
67
- Fix `addBlob!` calls for `FolderStore` and `InMemoryBlobStore` to use `BlobEntry.originId` and not previous bug `entry.id`.
78
- Close long running serialization redo (#590) using only JSON3.jl and StructTypes.jl going forward.

src/DataBlobs/services/BlobEntry.jl

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,16 @@ Get data entry
7777
Also see: [`addBlobEntry`](@ref), [`getBlob`](@ref), [`listBlobEntries`](@ref)
7878
"""
7979
function getBlobEntry(var::AbstractDFGVariable, key::Symbol)
80-
!hasBlobEntry(var, key) && error("No dataEntry label $(key) found in variable $(getLabel(var))")
80+
if !hasBlobEntry(var, key)
81+
throw(KeyError("No dataEntry label $(key) found in variable $(getLabel(var)). Available keys: $(keys(var.dataDict))"))
82+
end
8183
return var.dataDict[key]
8284
end
8385

8486
function getBlobEntry(var::AbstractDFGVariable, blobId::UUID)
8587
for (k,v) in var.dataDict
86-
if v.id == blobId
88+
# FIXME stop using v.id since that has been repurposed for unique BlobEntry indexing
89+
if v.originId == blobId || v.blobId == blobId || v.id == blobId
8790
return v
8891
end
8992
end
@@ -117,15 +120,15 @@ getBlobEntry(dfg::AbstractDFG, label::Symbol, key::Union{Symbol, UUID, <:Abstrac
117120
Add Data Entry to a DFG variable
118121
Should be extended if DFG variable is not returned by reference.
119122
120-
Also see: [`getBlobEntry`](@ref), [`addBlob`](@ref), [`mergeBlobEntries!`](@ref)
123+
Also see: [`getBlobEntry`](@ref), [`addBlob!`](@ref), [`mergeBlobEntries!`](@ref)
121124
"""
122125
function addBlobEntry!(
123126
var::AbstractDFGVariable,
124127
entry::BlobEntry;
125-
# see https://github.com/JuliaRobotics/DistributedFactorGraphs.jl/issues/985
126-
blobId::UUID = isnothing(entry.blobId) ? entry.id : entry.blobId ,
127-
blobSize::Int = hasfield(DistributedFactorGraphs.BlobEntry, :size) ? entry.size : -1 ,
128+
blobId::UUID = (isnothing(entry.blobId) ? entry.id : entry.blobId),
129+
blobSize::Int = (hasfield(BlobEntry, :size) ? entry.size : -1)
128130
)
131+
# see https://github.com/JuliaRobotics/DistributedFactorGraphs.jl/issues/985
129132
haskey(var.dataDict, entry.label) && error("blobEntry $(entry.label) already exists on variable $(getLabel(var))")
130133
var.dataDict[entry.label] = entry
131134
return entry

test/testBlocks.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -919,8 +919,8 @@ function DataEntriesTestBlock!(fg, v2)
919919
#get
920920
@test deepcopy(de1) == getBlobEntry(v1, :key1)
921921
@test deepcopy(de2) == getBlobEntry(fg, :a, :key2)
922-
@test_throws ErrorException getBlobEntry(v2, :key1)
923-
@test_throws ErrorException getBlobEntry(fg, :b, :key1)
922+
@test_throws KeyError getBlobEntry(v2, :key1)
923+
@test_throws KeyError getBlobEntry(fg, :b, :key1)
924924

925925
#update
926926
@test updateBlobEntry!(fg, :a, de2_update) == de2_update
@@ -998,8 +998,8 @@ function blobsStoresTestBlock!(fg)
998998
#get
999999
@test deepcopy(de1) == getBlobEntry(var1, :label1)
10001000
@test deepcopy(de2) == getBlobEntry(fg, :a, :label2)
1001-
@test_throws ErrorException getBlobEntry(var2, :label1)
1002-
@test_throws ErrorException getBlobEntry(fg, :b, :label1)
1001+
@test_throws KeyError getBlobEntry(var2, :label1)
1002+
@test_throws KeyError getBlobEntry(fg, :b, :label1)
10031003

10041004
#update
10051005
@test updateBlobEntry!(fg, :a, de2_update) == de2_update

0 commit comments

Comments
 (0)