Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

file.exists() should return a bool instead of always truthy [bool] #825

Closed
grayside opened this issue Aug 22, 2019 · 1 comment
Closed
Assignees
Labels
api: storage Issues related to the googleapis/nodejs-storage API. type: question Request for information or clarification. Not an issue.

Comments

@grayside
Copy link

As illustrated in the code comment, checking if a file exists can be done along these lines:

client.bucket(BUCKET).file(FILE).exists()

That's fantastically useful. However, the response from this method is not a bool as anyone looking at the function name would assume. Instead, it returns a bool wrapped in an array. This means the response always evaluates truthy.

Developers paying attention will realize something is wrong. Developers that do not test for missing files will ship broken code.

@yoshi-automation yoshi-automation added triage me I really want to be triaged. 🚨 This issue needs some love. labels Aug 23, 2019
@callmehiphop callmehiphop added type: question Request for information or clarification. Not an issue. and removed 🚨 This issue needs some love. triage me I really want to be triaged. labels Aug 28, 2019
@callmehiphop
Copy link
Contributor

Hi @grayside! Sorry you ran into this, it is a known quirk across all of our Node.js libraries. I don't think there is any planned work to change the method signatures, so I would suggest destructuring in the mean time.

const [exists] = await file.exists();

Hopefully this is not too big of an inconvenience.

@google-cloud-label-sync google-cloud-label-sync bot added the api: storage Issues related to the googleapis/nodejs-storage API. label Jan 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: storage Issues related to the googleapis/nodejs-storage API. type: question Request for information or clarification. Not an issue.
Projects
None yet
Development

No branches or pull requests

3 participants