stephenplusplus / google-auto-auth

Making it as easy as possible to authenticate a Google API request
MIT License
34 stars 9 forks source link

Promise was created in a handler but was not returned from it #28

Closed mcfarljw closed 6 years ago

mcfarljw commented 6 years ago
(node:13969) Warning: a promise was created in a handler at /node_modules/google-auto-auth/index.js:172:7 but was not returned from it, see http://goo.gl/rRqMUw
    at new Promise (/node_modules/bluebird/js/release/promise.js:79:10)

I've noticed this warning when using the google cloud datastore node library with bluebird as the promise library.

stephenplusplus commented 6 years ago

@ofrobots what should we do here?

ofrobots commented 6 years ago

@mcfarljw Would you have some code that reproduces this scenario? Do you see the error when running locally on your machine, or when deployed on GCP, or elsewhere?

ofrobots commented 6 years ago

I can reproduce the issue with the following code:

global.Promise = require('bluebird');
global.Promise.config({
  longStackTraces: true,
  warnings: true
});

const Datastore = require('@google-cloud/datastore');
const datastore = new Datastore();

const kind = 'Task';
const name = 'simpletask1';
const taskKey = datastore.key([kind, name]);

const task = {
  key: taskKey,
  data: {
    description: 'Buy milk'
  }
};

datastore.save(task)
  .then(() => {
    console.log(`saved ${task.key.name}: ${task.data.description}`);
  })
  .catch(console.error);
ofrobots commented 6 years ago

This is a spurious warning from bluebird. The code is actually correct as is. Bluebird thinks this code is missing a return of a promise:

https://github.com/stephenplusplus/google-auto-auth/blob/2d172a054725f79a51638c6f128f3259f1649daa/index.js#L116

Changing this to the following gets rid of the spurious warning:

 this.authClientPromise.then(callback.bind(null, null), callback);

This works as we are simply avoiding creating an extra promise for the call to .catch (which is where bluebird is getting confused about us maybe returning a promise in the then too).

I don't think this is a bug here (it is a bluebird issue IMO), but here's a work-around in case other people run into it: https://github.com/stephenplusplus/google-auto-auth/pull/29.