From 5fde608af4d6acd252685b3b75bcb696e4cf5b1a Mon Sep 17 00:00:00 2001 From: Christian Rorvik Date: Tue, 31 Oct 2023 11:14:26 +0100 Subject: [PATCH] Return a null field for missing fields (#31) --- src/reader.jl | 2 +- test/reader_tests.jl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/reader.jl b/src/reader.jl index 33f8e7a..4949f41 100644 --- a/src/reader.jl +++ b/src/reader.jl @@ -156,7 +156,7 @@ end offset = field_end end end - throw(KeyError(target)) + BSONReader(reader.src, 0, BSON_TYPE_NULL, reader.validator, reader.conversions) end # @noinline Base.@constprop :none function Base.getindex(reader::BSONReader, target::Union{AbstractString, Symbol}) diff --git a/test/reader_tests.jl b/test/reader_tests.jl index 5f6fe39..accb105 100644 --- a/test/reader_tests.jl +++ b/test/reader_tests.jl @@ -274,7 +274,7 @@ end writer["x"] = 123 close(writer) reader = BSONReader(buf) - @test_throws KeyError reader["y"] + reader["y"][Any] === nothing end @testset "foreach" begin