-
Notifications
You must be signed in to change notification settings - Fork 0
chore: Error handling when upload id I'd incorrect for Resumable upload #6
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -149,7 +149,7 @@ def initiate_resumable_upload(client) | |
| # Reinitiating resumable upload | ||
| def reinitiate_resumable_upload(client) | ||
| logger.debug { sprintf('Restarting resumable upload command to %s', url) } | ||
| check_resumable_upload client | ||
| return false unless check_resumable_upload client | ||
| upload_io.pos = @offset | ||
| end | ||
|
|
||
|
|
@@ -224,6 +224,10 @@ def check_resumable_upload(client) | |
| # Initiating call | ||
| response = client.put(@upload_url, "", request_header) | ||
| handle_resumable_upload_http_response_codes(response) | ||
| if response.status.to_i == 404 | ||
| logger.debug { sprintf("Failed to fetch upload session. Response: #{response.status.to_i} - #{response.body}") } | ||
| false | ||
| end | ||
| end | ||
|
|
||
| # Cancel resumable upload | ||
|
|
@@ -234,14 +238,13 @@ def cancel_resumable_upload(client) | |
| # Initiating call | ||
| response = client.delete(@upload_url, nil, request_header) | ||
| handle_resumable_upload_http_response_codes(response) | ||
|
|
||
| if !@upload_incomplete && (400..499).include?(response.status.to_i) | ||
| if !@upload_incomplete && (400..499).include?(response.status.to_i) && response.status.to_i != 404 | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it seems 404 check should be with or condition?
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes it comes in this condition but we want to perform additional actions in case of 404
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok for 404 else case will work?
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes |
||
| @close_io_on_finish = true | ||
| true # method returns true if upload is successfully cancelled | ||
| else | ||
| logger.debug { sprintf("Failed to cancel upload session. Response: #{response.status.to_i} - #{response.body}") } | ||
| false | ||
| end | ||
|
|
||
| end | ||
|
|
||
| def handle_resumable_upload_http_response_codes(response) | ||
|
|
||
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 change introduces a bug that breaks the resumable upload functionality. When the server responds with a 308 status (Resume Incomplete),
handle_resumable_upload_http_response_codescorrectly returnstrue. However, theifstatement on line 229 is the last expression in the method, and when its condition is false, it evaluates tonil. This causescheck_resumable_uploadto returnnil(a falsy value).As a result, in
reinitiate_resumable_upload, theunless check_resumable_upload clientcondition becomes true, causing the method to incorrectlyreturn falseinstead of proceeding with the upload.To fix this,
check_resumable_uploadmust explicitly return the result fromhandle_resumable_upload_http_response_codesfor non-404 cases.Uh oh!
There was an error while loading. Please reload this page.
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.
can you check this does handle_resumable_upload_http_response_codes is returning 404 specifically? @shubhangi-google
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.
no handle_resumable_upload_http_response_codes will not return 404 it sets the value of variable which tells if the ubload is complete or incomplete
handle_resumable_upload_http_response_codes sets the value of variable so that further processing can be done in other methods
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.
ok got it, the response object is filled in that method, and check 404 here, other than 404 it return true?
Uh oh!
There was an error while loading. Please reload this page.
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.
yes either it will return true or it will do further processing depending on the flow