You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
JSON::Builder.field with a block argument expects that in the block argument exactly one value is appended to the builder. This can obviously not be checked at compile time, but it should be possible to add a runtime check.
It is currently difficult to catch an error because this code:
builder.object do
builder.field "foo" { builder.string("bar") }
builder.field "baz", "bar"end
is effectively the same as
builder.object do
builder.string "foo"
builder.string "bar"
builder.string "baz"
builder.string "bar"end
If for some reason, the block does not append a value, the object creation gets messed up and fails with Missing object value (or Expected string for object name) when a non-string value is involved. This is hard to debug, because an error will raise somewhere later at a point where there is not really the issue.
I think it would be possible to raise an error if state.name is true at the end of field(name, &block), though I'd like to get some feedback on that idea.
The text was updated successfully, but these errors were encountered:
Not sure about field?, is there anything wrong with having that as the default behaviour? I mean for the absent value case it's still an easy to spot mistake given you got a null where you didn't expect one.
But in general either solution seems fine to me :)
JSON::Builder.field
with a block argument expects that in the block argument exactly one value is appended to the builder. This can obviously not be checked at compile time, but it should be possible to add a runtime check.It is currently difficult to catch an error because this code:
is effectively the same as
If for some reason, the block does not append a value, the object creation gets messed up and fails with
Missing object value
(orExpected string for object name
) when a non-string value is involved. This is hard to debug, because an error will raise somewhere later at a point where there is not really the issue.I think it would be possible to raise an error if
state.name
is true at the end offield(name, &block)
, though I'd like to get some feedback on that idea.The text was updated successfully, but these errors were encountered: