Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return a better error when a user tries to cast a document that has already been accessed to a value #2085

Merged
merged 4 commits into from Nov 26, 2023

Conversation

lemire
Copy link
Member

@lemire lemire commented Nov 23, 2023

In #2084, @mmatrosov reported an error with the following code...

      padded_string json(R"({"foo": "bar"})"sv);
      ondemand::parser parser;
      ondemand::document doc = parser.iterate(json);
      // Next line starts iterating through the document as an object, effectively
      // instantiating the object.
      std::string_view foo = doc["foo"];
      // This next line tries to a value instance representing the object as a value.
      // It is not allowed because the object instance is already in play.
      simdjson::ondemand::value value = doc;

Currently, this fails with a somewhat cryptic error "A JSON document made of a scalar (number, Boolean, null or string) is treated as a value" whether we compile in debug or release mode.

Compiling such code in debug mode should now return an OUT_OF_ORDER_ITERATION message which should help debugging.

I have also clarified the documentation.

doc/basics.md Outdated Show resolved Hide resolved
include/simdjson/generic/ondemand/document.h Outdated Show resolved Hide resolved
@lemire
Copy link
Member Author

lemire commented Nov 25, 2023

@mmatrosov Do you approve?

Copy link
Collaborator

@mmatrosov mmatrosov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, sorry, I did not think you was waiting for my approval

@lemire
Copy link
Member Author

lemire commented Nov 26, 2023

@mmatrosov Thanks.

@lemire
Copy link
Member Author

lemire commented Nov 26, 2023

This will be part of the next release.

@lemire lemire merged commit 3bb2f0a into master Nov 26, 2023
73 checks passed
@lemire lemire deleted the lemire/issue2084 branch November 26, 2023 19:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants