You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to write exception handling in case the object I want to get from my bucket isn't there. I tried to surround this in tryCatch:
tryCatch({
header<- head_object(object="s3://mybucket/not_there.txt")
}, error=function(e){
message("object not found")
# code to get around it
})
Unfortunately, when the object is not available, head_object returns a message saying "Client error: (404) Not Found" instead of an error, so there is nothing to catch. I've gotten around this by saying doing
suppressMessages(
header<-aws.s3::head_object(object="s3://mybucket/not_there.txt")
)
if(!header[1]){
message("object not found")
# code to get around it
}
because the first element in the returned object is a boolean indicating whether it was there or not, this works. But it feels unnatural. Is there a reason for this design decision? Is there a better way to handle exceptions?
By the way, I only came across this when I didn't find a function for check_exists(), which would seem to be a natural thing to have here.
The text was updated successfully, but these errors were encountered:
I want to write exception handling in case the object I want to get from my bucket isn't there. I tried to surround this in
tryCatch
:Unfortunately, when the
object
is not available,head_object
returns a message saying "Client error: (404) Not Found" instead of an error, so there is nothing to catch. I've gotten around this by saying doingbecause the first element in the returned object is a boolean indicating whether it was there or not, this works. But it feels unnatural. Is there a reason for this design decision? Is there a better way to handle exceptions?
By the way, I only came across this when I didn't find a function for
check_exists()
, which would seem to be a natural thing to have here.The text was updated successfully, but these errors were encountered: