Skip to content

Conversation

@pryrt
Copy link
Owner

@pryrt pryrt commented Jun 13, 2025

  • To address specifics of ozone10’s crash report ([BUG] Failed download causes crash #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

closes #13

- 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
@pryrt
Copy link
Owner Author

pryrt commented Jun 13, 2025

@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 { or [, for example), the exception is still caught and handled without crashing the plugin.

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 {
Copy link

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.

Copy link
Owner Author

@pryrt pryrt Jun 13, 2025

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)

Copy link

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.

image
image
image
image

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.

Copy link
Owner Author

@pryrt pryrt Jun 13, 2025

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)

Copy link

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 {
Copy link

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.

@ozone10
Copy link

ozone10 commented Jun 13, 2025

@pryrt
no more crash. 👍

@pryrt
Copy link
Owner Author

pryrt commented Jun 13, 2025

With the newest commit:

  • When populating the lists from the download, if it gets an internet error (like the firewall block), the download function will still give the first message box, and will then immediately return FALSE to the main dialog box.
  • If there is 404/500/etc when downloading Theme data, it will give a message box indicating there’s an error, and then try to move forward to the UDL (hoping that UDL will get valid data; since UDL is much more likely to be desired than Theme, I want to not stop a UDL download just because there’s a problem with the Theme info)
  • If there is a 404/500/etc when downloading the UDL data: if Theme already gave the error message box, just return FALSE at this point; if Theme didn’t give the error message, then UDL will give error message and then return FALSE.
  • If the list-populating exits with FALSE, then the main Dialog will close itself, because the user has already been informed of a problem.
  • If somehow the file list is empty and the user clicks DOWNLOAD, it will give an error message, not crash

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.

@ozone10
Copy link

ozone10 commented Jun 14, 2025

@pryrt
working great.

@pryrt pryrt merged commit d907c4f into main Jun 14, 2025
12 checks passed
@pryrt pryrt deleted the ozoneDownloadCrash branch June 14, 2025 20:20
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.

[BUG] Failed download causes crash

3 participants