Move de/serialization to ruby for easier error detection.

Closes open transactions if de/serialization fails for any reason,
avoiding the object to be in a potentially confused state.

Thanks to Michael Granger (ged@faeriemud.org) for the heads up and test case.

FossilOrigin-Name: e6e52675510533da8a26b0e2f0b2f73505a3b4ee0c94b123c37089489ed7745a
This commit is contained in:
Mahlon E. Smith 2021-10-06 20:43:13 +00:00
parent 6cc96d8fae
commit 25655d0554
4 changed files with 56 additions and 29 deletions

View file

@ -265,12 +265,22 @@ RSpec.describe( MDBX::Database ) do
it "reverts back to previous collection if the block raises an exception" do
expect( db.collection ).to be_nil
begin
expect {
db.collection( 'bucket1' ) do
db.collection( 'bucket2' ) { raise "ka-bloooey!" }
end
rescue
end
}.to raise_error( RuntimeError, /ka-bloooey!/ )
expect( db.collection ).to be_nil
end
it "reverts back to previous collection if serialization fails" do
db.serializer = ->( v ) { raise "ka-bloooey!" }
expect( db.collection ).to be_nil
expect {
db.collection( 'bucket1' ) do
db.collection( 'bucket2' ) {|sdb| sdb['foo'] = 1 }
end
}.to raise_error( RuntimeError, /ka-bloooey!/ )
expect( db.collection ).to be_nil
end