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

Error triggered but not surfaced when setting allow_missing_members or allow_unassigned_required_members #20

Closed
yahooguntu opened this issue Mar 29, 2022 · 3 comments

Comments

@yahooguntu
Copy link

I believe I found a bug when setting allow_missing_members or allow_unassigned_required_members. In the example below, parseTo() does indeed return an error (in one of my tests, a JS::Error::MissingPropertyMember), but when makeErrorString() is called it returns "Error NoError:".

#include "json_struct.h"
#include <iostream>

struct MyStruct {
  int a;
  int b;

  JS_OBJ(a, b);
};

int main() {
  std::string json = "{\"a\":1, \"c\": 3}";

  MyStruct my_struct;

  JS::ParseContext parse_ctx(json);

  parse_ctx.allow_missing_members = false;
  parse_ctx.allow_unnasigned_required_members = false;

  if (parse_ctx.parseTo(my_struct) != JS::Error::NoError) {
    std::cout << "Error parsing struct: " << parse_ctx.makeErrorString() << "\n";
  }

}

Output: Error parsing struct: Error NoError:

Expected: either a MissingPropertyMember or UnassignedRequiredMember error string, depending on the circumstances.

@jorgen
Copy link
Owner

jorgen commented Mar 30, 2022

Thank you for your bugreport. I will fix this tonight.

@jorgen
Copy link
Owner

jorgen commented Mar 30, 2022

Hello! Thank you again for your bugreport!
This should now be fixed.
https://godbolt.org/z/9rhTsrMa5
Please note that the JSON and C++ members leading to errors are accessible in the ParseContext through the members:

  std::vector<std::string> missing_members;
  std::vector<std::string> unassigned_required_members;

and that they are populated even though the allow_* members are true.

Please don't hesitate to file other bugs/requests.

@jorgen jorgen closed this as completed Mar 30, 2022
@yahooguntu
Copy link
Author

Thanks for the quick fix, and thanks for publishing such a great library!

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

No branches or pull requests

2 participants