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

[download-microservice] Improve Error Handling #130

Merged
merged 2 commits into from
Feb 1, 2024

Conversation

confused-Techie
Copy link
Member

This PR addresses the two issues we are seeing in the download microservice:

  • The releases object not being iterable. This object is defined by what GitHub returns so we have minimal control over it. While there is an error check for this step in the form of a try...catch handler, we can add a check here to validate we are working with an array, and if not return that we got improper data from GitHub. As well as log what we received, so that we can investigate the issue better.
  • When we work with the parameters provided by users, we previously would call just .split() on the value, not checking if we had received a string. When this occurs it was uncaught, causing the entire microservice to crash. Now we can validate we have a string or if not bail early.

@confused-Techie confused-Techie merged commit 0e2083d into main Feb 1, 2024
1 check passed
@confused-Techie confused-Techie deleted the improve-download-error-handling branch February 1, 2024 01:30
Copy link
Member

@DeeDeeG DeeDeeG left a comment

Choose a reason for hiding this comment

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

I'm late reviewing this since I was away for a couple of days, but thanks very much for the fix and this looks great to me!!

We can get maybe a less mysterious handling of this scenario for end-users of this microservice with this change, which makes it clearer that the issue isn't our fault if it happens to be e.g. GitHub's fault.

👍

Comment on lines +41 to +44
if (typeof raw !== "string") {
return false;
}

Copy link
Member

Choose a reason for hiding this comment

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

I am unsure if raw can possibly not be a string, since it starts with e.g. https://... and then the user-provided query parameters afterward.

That said, being conservative around that possibility feels more worthwhile than YOLOing if there is any remaining doubt -- And maybe there's a little doubt, so ultimately 👍 .

Copy link
Member Author

Choose a reason for hiding this comment

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

This change was actually in a reaction to us calling split() later on the raw value and crashing the microservice because the method wasn't available.

If I had to assume, the fact that it can be something not a string depends on how the HTTP handler built into NodeJS decodes this data, since I'm pretty sure we are accessing the parameters, rather than the full raw URL string

Copy link
Member

Choose a reason for hiding this comment

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

Ah, okay.

I think I got a bit confused by var names and code comments nearby.

Maybe I can think of a way to clarify the argument names, such as req here, and the path var name in the call site:

os: utils.query_os(path[1]),

As well as making this comment a bit less ambiguous, since I mistakenly read it as implying the argument would take the form https://...?param=val&param2=val2...:

let raw = req; // The URL string containing any number of query params.

Copy link
Member Author

Choose a reason for hiding this comment

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

@DeeDeeG So just double checked, and what you thought does have a lot of merit.

In index.js we take the path via req.url and split this on ?. Meaning we did at one point have the full path, as you envisioned it. But then we just pass the second part of that array to these query parameter handlers. Which, in the event there was nothing to actually split, and the resulting array has a single item, then we would be passing null meaning it's not a string.

So absolutely some better comments here and variables names aren't a bad idea.

microservices/download/utils.js Show resolved Hide resolved
@@ -38,6 +38,10 @@ function query_os(req) {
let raw = req; // The URL string containing any number of query params.
Copy link
Member

@DeeDeeG DeeDeeG Feb 1, 2024

Choose a reason for hiding this comment

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

Suggested change
let raw = req; // The URL string containing any number of query params.
let raw = req; // The query string containing any number of query params.

This would clarify it a bit for me, personally.

https://en.wikipedia.org/wiki/Query_string

Copy link
Member Author

Choose a reason for hiding this comment

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

Not a bad suggestion, I'll probably try to clean up this code just a little bit in the near future

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.

2 participants