googleapis / google-api-nodejs-client

Google's officially supported Node.js client library for accessing Google APIs. Support for authorization and authentication with OAuth 2.0, API Keys and JWT (Service Tokens) is included.
https://googleapis.dev/nodejs/googleapis/latest/
Apache License 2.0
11.27k stars 1.91k forks source link

Does `bucket.file(...).save(buffer)` throw on error? #3399

Closed heyarne closed 6 months ago

heyarne commented 7 months ago

Hi,

The docs for File.save seem to imply that the promisified version of the method throws an error when saving is not successful. I assumed so because it's common for other promisified APIs where the callback-based version matches the NodeJS convention of reserving the first callback parameter for a possible error.

Nevertheless I have just been bitten by code like this:

console.log('before saving')
await bucket.file(path).save(buffer)
console.log('after saving')

This ran from top to bottom and did not throw any error even though the file was not stored in the bucket. Is this intentional? Did I hit a bug?

If this is intentional, should I explicitly check whether saving was successful myself or what is the suggested pattern? The following does not work because save returns a Promise<void>:

const err = await bucket.file(path).save(buffer)

Thanks!

danielbankhead commented 6 months ago

Hey @heyarne, we provide a better storage experience in @google-cloud/storage rather than the @googleapis/storage library:

The @google-cloud/storage library shouldn't have the mentioned issue.