nodejs-storage: Error message in Node.js console is not the orignial error message

Environment details

  • OS: Windows 10
  • Node.js version: v8.9.4
  • npm version: 5.8.0
  • @google-cloud/storage version:

Steps to reproduce

  1. Not quite sure since I seem to have done something wrong. Anyway this is more general. I am using Formidable to try to upload an audio file to a gcs bucket. For some reason @google-cloud tries to parse this as JSON. That is probably my fault and not the issue here.

The issue is the error message in the console from the local Firebase web server. I get the error

“ApiError: Error during request.”

This is not very helpful, of course 😦 Fortunately you can get a trace with “console.log”. The error is thrown in

functions\node_modules@google-cloud\storage\node_modules@google-cloud\common\src\util.js:193:32

and this line looks like this:

  parsedHttpRespBody.err = new util.ApiError('Cannot parse JSON response');

I think it would be much easier for a developer if this error was made visible directly (instead of " ApiError: Error during request").

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 22 (14 by maintainers)

Commits related to this issue

Most upvoted comments

Many thanks for the example script - I’ve used it and could not reproduce until … I worked with a variety of files.

The error from GCS in our case was the following string: Metadata part is too large.

The actual error is the same as reported earlier in this issue: the response body isn’t parsable as JSON.

This is caused by passing metadata which contained a Buffer, due to an image file containing an image profile:

gcs.bucket('my-bucket').file('my-file-path').createWriteStream({
  contentType: 'image/jpeg',

  // metadata object containing data which shouldn't be passed to GCS
  metadata: {
    icc: <Buffer 00 09 fc ... >,
  },
});

We’ve stripped this from the metadata since it makes no sense storing that kind of information in GCS; all is working perfectly fine now.

I think this could have been detected way earlier if either the API endpoint returns JSON, or if the original error is thrown in util.js. Possible improvement?

@kinwa91 - can you take a crack at trying to reproduce this?

@adriaanmeuris While @lborgman and you are getting the same error, the original cause was discovered and resolved. Would you mind opening a new issue with reproduction steps or even a small repo or gist I can clone, npm install, and run? I do appreciate you finding this issue though, so we can link them together!