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

feat: Provide preview of JSON when Parse fails #131

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

dyastremsky
Copy link
Contributor

Parse is used across the Triton codebase. When Parse is failed, all the user sees is the error type and index. To help with debugging, provide a preview of the parsed JSON.

@dyastremsky dyastremsky self-assigned this Feb 26, 2025
@dyastremsky dyastremsky force-pushed the dyas-clearer-parser-errors branch from 35b1acf to 82a1897 Compare February 26, 2025 19:31
Clean up formatting
@dyastremsky dyastremsky force-pushed the dyas-clearer-parser-errors branch from d8177bd to c134020 Compare February 26, 2025 19:44
Comment on lines 214 to 219
// Show part of the JSON to help debugging
const size_t preview_length = 100;
std::string json_preview = json.substr(0, preview_length);
if (json.size() > preview_length) {
json_preview += "...";
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Any strong reason to not just include the whole thing?

For example, can the error start at some point after the preview length?

{... /* 100+ chars */, "my_invalid_json".123}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wanted to avoid that in case the JSON might be very long and crashes the program. I can increase the preview length to the limit of your choice (maybe std::numeric_limits<std::size_t>::max()or print the whole thing. Any preference?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is a fair point that it could very well be an issue after the 100th character. A large limit could resolve that while balancing the risk of the JSON being too long and causing a crash.

@@ -184,6 +184,12 @@ class TritonJson {
std::string(GetParseError_En(document_.GetParseError())) + " at " +
std::to_string(document_.GetErrorOffset())));
}
TRITONJSON_STATUSTYPE status =
ParseErrorHandler(document_, std::string(base, size));
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a before/after example in the PR description to highlight the new error/UX improvement?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure! Let me run it through CI then. I wanted your feedback first in case there was a reason not to do this.

@rmccorm4 rmccorm4 requested a review from ziqif-nv February 26, 2025 20:46
@rmccorm4 rmccorm4 changed the title Provide preview of JSON when Parse fails feat: Provide preview of JSON when Parse fails Feb 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants