On Sunday, 15 July 2012 at 22:42:03 UTC, David Eagen wrote:
Looks like isNull() isn't working, at least not from my diet
page. In the data it is processing the first three entries
contain the field but the fourth does not which generates the
error.
- auto endVerseBson = bsonDoc["endVerse"];
- if(!endVerseBson.isNull())
- {
- import std.stdio;
- writeln("Type for endVerse is ", endVerseBson.type);
- float endVerse;
- deserializeBson!float(endVerse, endVerseBson);
- formattedWrite(referenceAppender, "-%0g", endVerse);
- }
When run yields:
Type for endVerse is Double
Type for endVerse is Double
Type for endVerse is Double
Type for endVerse is Null
[7F17E05F6017:7F17E05F4317 ERR] Error after page has been
written: BSON value is type 'Null', expected to be one of
[Double]
It's getting even stranger. I added logging of the result of
isNull() to the if statement:
- auto endVerseBson = bsonDoc["endVerse"];
- if(!(endVerseBson.isNull()))
- {
- import std.stdio;
- writeln("endVerseBson isNull() => ", endVerseBson.isNull());
- writeln("Type for endVerseBson is ", endVerseBson.type);
...
endVerseBson isNull() => false
Type for endVerseBson is Double
endVerseBson isNull() => false
Type for endVerseBson is Double
endVerseBson isNull() => false
Type for endVerseBson is Double
endVerseBson isNull() => true
Type for endVerseBson is Null
[7FAC5427F0AC:7FAC5427D3AC ERR] Error after page has been
written: BSON value is type 'Null', expected to be one of [Double]
So, isNull is correctly true inside the if but incorrectly false
when testing for the if condition.
Since I'm doing this inside a Diet template I thought maybe there
was something bugged there so I tried using isNull in a regular D
function. It works correctly there. So this problem appears to be
only occurring when using Diet.
I'm using the latest version of Vibe.d from git (pulled today
just after the 0.7.6 release) and DMD 2.059 on Linux 64-bit.