Skip to content

vision: return errors#1334

Merged
callmehiphop merged 7 commits intogoogleapis:masterfrom
stephenplusplus:spp--1333
Jun 2, 2016
Merged

vision: return errors#1334
callmehiphop merged 7 commits intogoogleapis:masterfrom
stephenplusplus:spp--1333

Conversation

@stephenplusplus
Copy link
Contributor

@stephenplusplus stephenplusplus commented May 20, 2016

Fixes #1333

To Dos

  • Docs
  • Tests
    • Unit
    • System

If the Vision API fails to annotate an image, it returns an error (see https://cloud.google.com/vision/reference/rest/v1/images/annotate#annotateimageresponse) for each failed annotation. However, it will still annotate what it can.

vision.detect('malformed-image.jpg', ['faces', 'labels'], function(err, detections) {
  err === null
  detections === {
    faces: [/* successful annotation */],
    labels: [], // nothing, this failed
    errors: [/* error(s) from the request */]
  }
});

To add on errors to a single feature was a bit more complex:

vision.detect('malformed-image.jpg', ['faces'], function(err, detections) {
  err === null
  detections === [] // nothing, this failed
  detections.errors = [/* error(s) from the request */]
});

@stephenplusplus stephenplusplus added don't merge api: vision Issues related to the Cloud Vision API. labels May 20, 2016
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label May 20, 2016
@stephenplusplus
Copy link
Contributor Author

stephenplusplus commented May 23, 2016

@callmehiphop honest talk time. The code in Vision.prototype.detect is kind of out of control. Considering this latest refactoring: https://gist.github.com/stephenplusplus/aa0c82b4939e5901680e41c9a89e8c03 -- can you think of a way I can trim down the insanity?

@callmehiphop
Copy link
Contributor

What are your feelings on moving things outside of the function? We have several maps and inner functions used to massage data that could easily live as a static/private members.

@stephenplusplus
Copy link
Contributor Author

stephenplusplus commented May 23, 2016

I made an attempt at moving them outside as static members. The issue I ran into was losing access to variables that held the original response, the types the user originally requested, and the shorthand->formalApiName lookup tables. I'll just leave things like they are in the gist for now, and move on with this PR. If I can't come up with a good refactoring plan before we merge, I'll be sure to open an issue about it to hit in the future.

@stephenplusplus
Copy link
Contributor Author

@callmehiphop ready to go. See the updated first post for the .errors possible weirdness.

@callmehiphop
Copy link
Contributor

I think overall the code looks good, I'm not sure how else you would solve this problem. My only real critique is that the documentation for this seems like it would be easily overlooked. I know we generally don't highlight error handling in the doc examples, but what are your feelings on creating an additional example showing how to handle errors when dealing with a malformed image?

@stephenplusplus
Copy link
Contributor Author

Example added!

@coveralls
Copy link

coveralls commented Jun 2, 2016

Coverage Status

Coverage remained the same at 100.0% when pulling 6398a54 on stephenplusplus:spp--1333 into 7ff0a5b on GoogleCloudPlatform:master.

* });
*
* //-
* // To handle errors that occurred, check the length of the `errors` array.

This comment was marked as spam.

This comment was marked as spam.

@callmehiphop callmehiphop merged commit a0da750 into googleapis:master Jun 2, 2016
miguelvelezsa pushed a commit that referenced this pull request Jul 23, 2025
Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
sofisl pushed a commit that referenced this pull request Feb 3, 2026
* vision: return errors

* tests

* test coverage fixer

* tests

* docs

* add error handling example

* elaborate error handling
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: vision Issues related to the Cloud Vision API. cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants