-
Notifications
You must be signed in to change notification settings - Fork 4
CollectionInterface: add JSON error handling to avoid plugin crash #14
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
Conversation
- To address specifics of ozone10’s crash report (#13), check to make sure that char-vector after download is >0 characters and has the right first character for JSON ([ or {, depending on download). - Also add exception handling around the JSON parsing and data crunching, in case there are other problems that I have not anticipated
|
@ozone10, feel free to test out the artifact. During my debug, when I forced download problems (404 errors, empty return vector), it properly caught and showed a MessageBox without crashing the plugin. And if I force JSON errors (mismatched This should be sufficient for your problem, and future JSON-parsing issues. |
| // issue#13: don't try to parse if there is no data to parse | ||
| ::MessageBox(_hwndNPP, L"Problems downloading Themes Collection information.\nYou might want to check your internet connection.", L"Download Problems", MB_ICONWARNING); | ||
| } | ||
| else { |
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.
I would use only if (!vcThemeJSON.empty()) and remove current if block,.
I don't expect .toc.json file content to be wrong.
In
| std::vector<char> CollectionInterface::downloadFileInMemory(const std::wstring& url) |
there are already message boxes with error description, and here seems to be redundant, And it can be annoying when you have to dismiss 4 message boxes and in the end get empty listbox.
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.
I would use only
if (!vcThemeJSON.empty())
This would not catch the problem of GitHub sending a 404 or server error, because the vector will actually be the string of the error code (like 404 Not Found)
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.
This would not catch the problem of GitHub not sending you any data: when there is a download error, the vector is not empty, it gives the HTTP error code (like 404 Not Found)
I see in that case you can add check for empty vector, to reduce message boxes.
In what situation does it give four message boxes? I can see that it might give 2 -- one for themes and one for UDL -- but I cannot see how it could possibly give 4.
I have a firewall configured to block applications the first time they try to connect to net, so I can to decide whether to allow them.
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.
And it can be annoying when you have to dismiss 4 message boxes and in the end get empty listbox.
It took me a while to figure out how there could be 4 message boxes. But I'm assuming now that your reported "connection is blocked" was actually one of the "Could not connect to internet when trying to download" message boxes that the plugin launches from inside the downloadFileInMemory() function.
Now that I think I've figured that out, I can figure out a good way to non-annoyingly handle that condition -- while still preventing other possible problems, like a 404 or 500 error from the GH server, or receiving junk rather than JSON for unknown reasons. (Because there are multiple types of errors, there will still be the extra indentation -- but since it's my code, I will do the blocks the best way for me to understand for future maintenance)
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.
Another issue when clicking on "Download" button with empty listbox notepad++ will crash.
| // issue#13: don't try to parse if there is no data to parse | ||
| ::MessageBox(_hwndNPP, L"Problems downloading UDL Collection information.\nYou might want to check your internet connection.", L"Download Problems", MB_ICONWARNING); | ||
| } | ||
| else { |
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.
Same as with vcThemeJSON but instead I would use
if (vcUdlJSON.empty())
{
return;
}to return early and reduce indentation level for next block for better readability.
|
@pryrt |
|
With the newest commit:
That means that it should do, at most, 1 message box saying something went wrong; it shouldn't show the download-dialog if there isn't good UDL data for populating the lists; and if one of the lists is still empty (like the Theme list), accidentally hitting DOWNLOAD should warn the user instead of crash. I believe this addresses all your concerns. |
|
@pryrt |




closes #13