Closed stuvet closed 2 years ago
The approach looks good, to your questions
- I am not entirely happy that all httr errors would now be propagated back to be retried - seems unnecessary, and you could just limit it to 400. - would prefer it to be only 400 status codes.
There are custom error classes for gar_api_generator()
functions that would return a try exception http_400
which is missed using PUTme()
, I may look at adding that. The relevant code in googleAuthR
is https://github.com/MarkEdmondson1234/googleAuthR/blob/297e17847a07a55c80e80d8382342c8f383afdf9/R/utility.R#L2-7
abort_http <- function(status_code, msg = NULL){
myMessage("Custom error", status_code, msg, level = 2)
rlang::abort(paste0("http_",status_code),
message = paste0("http_", status_code, " ", msg)
)
}
and then used via
tryCatch(blah(), http_400 = function(err) message("A 400 error! do something"))
- Are you happy to expose the httr errors to the end user if they called gcs_retry_upload directly?
yes
- I have not yet had a chance to test this with targets, so it may not fix my original problem!
please do try it to make sure, ideal would be a test that fails now but is fixed by your new code.
I'm really sorry I missed this.
I used this reprex to validate this PR.
I'll put together a more targets
focussed test tomorrow, but I've been using this PR for the last 7 days while developing a ~1400 target pipeline with ~600 of the targets creating files >5MB (many multi-GB).
The same pipeline previously triggered that error every time a certain collection of targets ran but hasn't yet been repeated since this change.
Thanks, is this then confirmed to fix #122 ?
Submitted in response to https://github.com/cloudyr/googleCloudStorageR/issues/122#issuecomment-1192741059
Sorry about so many diffs - this was caused by running
devtools::document()
. I only changed lines 543 & 614-615 ofuploads.R
& included thehttr::http_error
function. Feel free to decline this one & fix it in a neater/different way. I'm not quite satisfied this approach.Problems
predefinedAcl='private'
is incorrectly set for a bucket which has uniform ACL.According to the api reference, when a predefinedAcl is supplied to a bucket with uniform permissions a
400
status code is returned.In
gcs_retry_upload
, whenpredefinedAcl='private'
is incorrectly supplied for abucketLevel
bucket:Current Behaviour
upload_status <- PUTme
call returns a400
status_code with an error message starting"Cannot insert legacy ACL..."
else
clausestop("Couldn't get upload status")
.error
clause of thetryCatch
ingcs_upload
if(!grepl("Cannot insert legacy ACL", err$message)) {...
condition, which prevents any retry, throwing the error instead.Other potential issues:
gcs_retry_upload
return the same error message to the user. It may be more helpful to return the original error message, assuming it exists, and leave unhandled, non-error codes to trigger the 'Couldn't get upload status' message.Proposed Behaviour
upload_status <- PUTme
call returns a400
status_code with an error message starting"Cannot insert legacy ACL...
else if (httr::http_error(upload_status)) {...
clausehttr
error messageerror
clause of thetryCatch
ingcs_upload
if(!grepl("Cannot insert legacy ACL", err$message)) {...
condition, so resumable uploads are reattempted withpredefinedAcl='bucketLevel'
, to match the simple upload behaviour.Concerns
400
.gcs_retry_upload
directly?targets
, so it may not fix my original problem!