diff --git a/lib/common/api/deprecate.js b/lib/common/api/deprecate.js index 42218003f78c..e61fb2b9fef4 100644 --- a/lib/common/api/deprecate.js +++ b/lib/common/api/deprecate.js @@ -89,7 +89,9 @@ const deprecate = { cb.length === 2 ? cb(null, res) : cb(res) }) }, err => { - process.nextTick(() => cb(err)) + process.nextTick(() => { + cb.length === 2 ? cb(err) : cb() + }) }) } }, diff --git a/spec/api-deprecations-spec.js b/spec/api-deprecations-spec.js index 7236107f262d..ebaa616fb872 100644 --- a/spec/api-deprecations-spec.js +++ b/spec/api-deprecations-spec.js @@ -145,6 +145,24 @@ describe('deprecations', () => { expect(warnings).to.have.lengthOf(0) }) + it('only calls back an error if the callback is called with (err, data)', (done) => { + enableCallbackWarnings() + let erringPromiseFunc = () => new Promise((resolve, reject) => { + reject(new Error('fail')) + }) + erringPromiseFunc = deprecate.promisify(erringPromiseFunc) + + erringPromiseFunc((err, data) => { + expect(data).to.be.an('undefined') + expect(err).to.be.an.instanceOf(Error).with.property('message', 'fail') + erringPromiseFunc(data => { + expect(data).to.not.be.an.instanceOf(Error) + expect(data).to.be.an('undefined') + done() + }) + }) + }) + it('warns exactly once for callback-based invocations', (done) => { enableCallbackWarnings() promiseFunc = deprecate.promisify(promiseFunc)