-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
CharReader: Add StructuredError #1409
Conversation
Out of curiosity, what's the status of this PR? We'd find this addition useful as well. |
I have some pending comments that I never hit "Send" on. Sorry about that. |
90c3080
to
59780d8
Compare
@BillyDonahue I responded to all the comments from your last review. Let me know if you have any questions. |
28477f4
to
4c0a5ef
Compare
Thank you for the quick review @BillyDonahue |
fedff8c
to
e9e3306
Compare
@BillyDonahue thanks for your review, I've addressed these comments. |
I still see some comments unaddressed. |
Which comments are unaddressed? Is the problem that I didn't click resolve
on the comments?
I did notice another indentation error though which I will commit now.
…On Tue, Oct 11, 2022 at 5:23 AM Billy Donahue ***@***.***> wrote:
@BillyDonahue <https://github.com/BillyDonahue> thanks for your review,
I've addressed these comments.
I still see some comments unaddressed.
—
Reply to this email directly, view it on GitHub
<#1409 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AZKCO2OVQIT6JHRG7X37HNDWCUWYVANCNFSM5YAQMQ4Q>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
f9ebf1f
to
63a42d7
Compare
Please look through some of those comments. I think you'll see what I mean. |
The comment you responded to was addressed elsewhere in the code. I added some comments to the issues not showing as Outdated to explain how these were addressed. In the future, I'll make sure to include a description of how the comments were addressed to make it more straightforward to review. |
@BillyDonahue can you take a look at this comment and let me know if there are still changes you are waiting on from me, or if you just haven't gotten a chance to review them yet? |
Sorry it's very hard to follow Github PR reviews, so if something is addressed elsewhere I may not make the connection. I will take another deeper look. |
63a42d7
to
804d8f0
Compare
src/lib_json/json_reader.cpp
Outdated
@@ -900,7 +900,7 @@ class OurReader { | |||
bool parse(const char* beginDoc, const char* endDoc, Value& root, | |||
bool collectComments = true); | |||
String getFormattedErrorMessages() const; | |||
std::vector<StructuredError> getStructuredErrors() const; | |||
std::vector<OurReader::StructuredError> getStructuredErrors() const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert. we're in OurReader's class scope already
src/lib_json/json_reader.cpp
Outdated
std::vector<CharReader::StructuredError> getStructuredErrors() const override { | ||
std::vector<OurReader::StructuredError> errors = reader_.getStructuredErrors(); | ||
std::vector<CharReader::StructuredError> out_errors; | ||
std::transform(errors.begin(), errors.end(), std::back_inserter(out_errors), | ||
[](OurReader::StructuredError x) { | ||
CharReader::StructuredError y; | ||
y.offset_start = x.offset_start; | ||
y.offset_limit = x.offset_limit; | ||
y.message = x.message; | ||
return y; | ||
}); | ||
return out_errors; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be written more economically, but I think the translation can be made unnecessary.
std::vector<CharReader::StructuredError> getStructuredErrors() const override { | |
std::vector<OurReader::StructuredError> errors = reader_.getStructuredErrors(); | |
std::vector<CharReader::StructuredError> out_errors; | |
std::transform(errors.begin(), errors.end(), std::back_inserter(out_errors), | |
[](OurReader::StructuredError x) { | |
CharReader::StructuredError y; | |
y.offset_start = x.offset_start; | |
y.offset_limit = x.offset_limit; | |
y.message = x.message; | |
return y; | |
}); | |
return out_errors; | |
} | |
std::vector<CharReader::StructuredError> getStructuredErrors() const override { | |
std::vector<CharReader::StructuredError> out; | |
auto in = reader_.getStructuredErrors(); | |
out.reserve(in.size()); | |
for (auto&& x : in) | |
out.push_back({x.offset_start, x.offset_limit, std::move(x.message)}); | |
return out; | |
} |
But I don't see the need for the extra translation step.
There doesn't need to be a separate type for OurReader::StructuredError
now that there's a CharReader::StructuredError
. This OurReader
is a private detail of this .cpp file, and its only purpose is to serve as an implementation detail of OurCharReader
. It can be made to produce CharReader::StructuredError
structs directly.
A great thing about OurReader
is that it's 100% an implementation detail of the .cpp file and we can change it without worrying about API breaks. I didn't realize this before, which wasted your time perhaps. Apologies.
I feel like the Our
stuff makes the library pretty confusing to work on and we should just make clean break from the deprecated Reader by putting it in another file where it can't bother us anymore. :)
include/json/reader.h
Outdated
virtual std::vector<StructuredError> getStructuredErrors() const = 0; | ||
}; | ||
|
||
CharReader(Impl* impl) : _impl(impl) { } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
My suggestion was to accept a
std::unique_ptr<Impl>
here. -
Unary constructors should be
explicit
.
CharReader(Impl* impl) : _impl(impl) { } | |
explicit CharReader(std::unique_ptr<Impl> impl) : _impl(std::move(impl)) { } |
src/lib_json/json_reader.cpp
Outdated
bool ok = reader_.parse(beginDoc, endDoc, *root, collectComments_); | ||
if (errs) { | ||
*errs = reader_.getFormattedErrorMessages(); | ||
: CharReader(new OurImpl(collectComments, features)) {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
: CharReader(new OurImpl(collectComments, features)) {} | |
: CharReader(std::make_unique<OurImpl>(collectComments, features)) {} |
6ccfec6
to
0056697
Compare
@BillyDonahue let me know if these changes address your comment |
@BillyDonahue it's been 8 weeks since your last update on this. Is there anything you're waiting on from me? |
Sorry. I made a few suggestions and didn't hear back. If you have resolved them can you comment and resolve? |
@BillyDonahue I see this marked as approved. Is there a release timeline that I can expect for these changes to get merged? |
Sorry I thought the approval was sufficient for you to merge it rather than me. |
Hm. I don't actually know how to restart the stuck Travis CI job. |
Add getStructuredError to CharReader
@BillyDonahue I squashed the commits and pushed to try to retrigger the CI job. I don't think I can merge this as I don't have write access to the repository. I'm also wondering if there can be a minor version increase when this and #1412 are merged so that we can detect versions with these updates. |
The move from Json::Reader to Json::CharReader omitted the ability to get structured error messages from the parser. Clients which want to extract the line and column information have to parse the returned string. Add a new getStructuredErrors() method which exposes the error as structured data instead of a string.
Based on the work from @KyleFromKitware and comments from @BillyDonahue on #1281.