-
Notifications
You must be signed in to change notification settings - Fork 264
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
self-update: better network error handling #580
Conversation
By using curl's -f option, we improve the self-update mechanism by not overwriting the fisher script if the HTTP status code given to us by Github is higher than 400. Additionally, we make sure that the exit code of the curl process must be always zero for the self-update to succeed.
Why do we need to duplicate error handling -- where do we fail here? Lines 162 to 167 in 994506e
|
I really had considered removing that check, but curl's But what if something goes really wrong with Github servers and they give us a 3xx code? We're currently not using curl's In this case I think it's better be safe than sorry. Also, that's an useful check in case Thoughts? |
@guihkx Gotcha. Could there be a way to get whatever curl gives us, and use awk to validate the file avoiding handling errors twice? If you could list up any of the possible error responses, I could provide the correct awk incantations. |
I just learned that we can use curl to give us the HTTP status code directly to
If the output is different than I mean, I think it's safe to assume that if we get a HTTP 200 OK code, the content is "trustworthy". Then that second check could be fully removed. |
@guihkx Interesting, where would that leave us? |
I just pushed the modifications I did. It only does a single check now: unless we get a 200 OK, the self-update will abort with an error: I personally think the changes are sane, but let me know if you think it's "too much". By the way, I'm not that familiar with the |
@guihkx Whoops, I think I miscommunicated here. I'm trying to both eliminate duplication (#580 (comment)) and keep the code simple. Now, there's more code than in your original PR. 😅 If possible, I'd like to dump whatever curl returns in a temporary file, then use awk to validate the content. |
Ohhhh, gotcha now! 😆 But when you say "validate the content", are you intending to check if output given by curl is an actual, valid, fish script? If that's the case, I think it sounds too complicated and I have no idea how can we do that properly. Maybe if fish has a tool for validating the syntax of their scripts or something like that...? |
It has something "close", have you looked at What we are doing right now is grabbing the version number from the file with awk. Do you know how that awk script doesn't fail even when curl does? I understand that's part of the problem we have here. |
I took a quick look on its documentation right now, but I'm not sure how it would be useful...? However, the fish manual pointed me to the
It seems pretty fast, too:
Testing with a random, non-script file (500 KiB):
Could that be used instead?
I think I do. As I mentioned in #578, Github went through a power outage and this is the raw response their server was giving me:
Running that output on
In order for the self-update to fail, the output of the command above would have to be an empty string, right? |
@guihkx Hmm, then this might just be everything we need: set -l next_version (command awk '$4 ~ /^[0-9]+\.[0-9]+\.[0-9]+$/ { print v=$4 } { exit !v }' <$file.) Could you check? UPDATE: Fixed regex! |
I was just about to suggest using regex, but I had no idea on how to do that with awk. x) Does fisher follow semantic versioning? For instance that check would fail if you released version 3.10.1. |
@guihkx Yes, whoops, my bad. This should work: awk '$4 ~ /^[0-9]+\.[0-9]+\.[0-9]+$/ { print v=$4 } { exit !v }' |
Just tested it, looks good! Don't forget to squash this whole mess before merging. 😅 Thanks a bunch! |
This will help us determine whether or not Github servers gave us a valid response, in order to the update mechanism to proceed. Co-authored-by: Jorge Bucaran <mail@jorgebucaran.com>
By using curl's
-f
option, we improve the self-update mechanism by not overwriting the fisher script if the HTTP status code given to us by Github is higher than 400.Additionally, we make sure that the exit code of the curl process must be always zero for the self-update to succeed.
The
-S
option, when used with-s
, allows us to get an error message from curl when it fails.A few examples:
Fixes #578