appengine
appengine copied to clipboard
Error handling ?
Howdy, I could not find anything on error handling.
How do you handle errors in there ? Are they typed ?
Thanks !
I'd like to avoid using things like :
if err.Error() == `API error 8 (images: OBJECT_NOT_FOUND)` {
But that error is of type *internal.APIError
. . .
Can I help ? Cheers !
Is there a specific error you're trying to check for? Can you share the bit of code that is failing with the opaque error?
The specific code is:
url, err := image.ServingURL(ctx, k, &image.ServingURLOptions{Secure: true})
if err != nil {
switch err.Error() {
case `API error 8 (images: OBJECT_NOT_FOUND)`:
rw.WriteHeader(http.StatusNotFound)
....
default:
rw.WriteHeader(http.StatusInternalServerError)
}
return
}
This handler redirects to the serving url of a storage image. But it's public, and I wanted to be able to differentiate between something wrong and a 404 image.
Just looking at https://godoc.org/google.golang.org/appengine/image tells that there is no error handling possible nor any documentation on error handling
We're noticing that OBJECT_NOT_FOUND
error as well for a Golang app deployed on AppEngine.
The associated code is
ctx := appengine.NewContext(r)
objectName := fmt.Sprintf("%s", "/gs/"+bucketID+"/"+objectID)
key, err := blobstore.BlobKeyForFile(ctx, objectName)
if err != nil {
log.Infof(ctx, "Couldn't generate BlobKeyForFile for resource %v with Error: %v", objectName, err)
http.Error(w, "blobstore.BlobKeyForFile : "+err.Error(), http.StatusUnprocessableEntity)
}
res, err := image.ServingURL(ctx, appengine.BlobKey(key), &image.ServingURLOptions{Secure: true})
For every single case we've noticed in the logs for that error, the file actually exists in the bucket.
The error we're getting is:
Couldn't get serving_url for resource /gs/BUCKET_NAME/OBJECT_NAME with Error: API error 8 (images: OBJECT_NOT_FOUND)
The error is happening randomly when calling image.ServingURL
.
Note that the general process goes as follows:
- Get signed URL
- Send PUT request to that signed URL to create the file in the bucket
- Upon success of the PUT request, send a request for the serving URL
We haven't been able to find a good reproduction case for that, though we've noticed that transparent PNG and heavier files (to the tune of 4MB up to 10MB) tend to fail more often, but this is merely an empirical observation on our part. We tried adding retries to the calling code (with incremental waiting between calls), to no avail.
The general error rate is around 5%, so it works just fine most times, but 100% success would be much better 😀
Hello !
We're experiencing the same issue in our application. Did you manage to find any way to solve this issue ?
Thanks :)
Here is a link to the OBJECT_NOT_FOUND issue https://github.com/golang/appengine/issues/123