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

fix: allow excluding accessor methods #228

Merged

Conversation

stephenplusplus
Copy link
Contributor

While working on googleapis/nodejs-bigtable#794, I noticed some accessor methods were being unexpectedly called by this module, even though they were excluded. Example:

class Backup {
  // ...
  get expireDate() {
    throw new Error('Should not be called')
  }
}

// ...

promisifyAll(Backup, { exclude: ['expireDate'] });
// throws "Should not be called"

This is because of the ordering which this module checks what methods from a prototype should be excluded:

  1. Is it a function?
  2. Is it a stream, or the constructor? Something that can't be promsified?
  3. Was it in the "exclude" array?

In this case, step 1 was what caused the error:

typeof Backup.prototype.expireDate
// throws "Should not be called"

The easiest way to solve this seemed to be to just bump step 3 up to step 1-- if the user wants it excluded, why do any other guessing?

@stephenplusplus stephenplusplus requested a review from a team as a code owner September 4, 2020 14:24
@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Sep 4, 2020
@codecov
Copy link

codecov bot commented Sep 4, 2020

Codecov Report

Merging #228 into master will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #228   +/-   ##
=======================================
  Coverage   91.28%   91.28%           
=======================================
  Files           3        3           
  Lines         264      264           
  Branches       37       39    +2     
=======================================
  Hits          241      241           
  Misses         23       23           
Impacted Files Coverage Δ
src/index.ts 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 90cc4c4...c8aa45c. Read the comment docs.

@stephenplusplus stephenplusplus merged commit 114d8bc into googleapis:master Sep 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants