Repository: serverless/serverless (JavaScript) — Bug Fix

Issue:
v1.48.1 triggers Bluebird promise warning when NODE_ENV=development
<!--
1. If you have a question and not a bug report please ask first at http://forum.serverless.com
2. Please check if an issue already exists. This bug may have already been documented
3. Check out and follow our Guidelines: https://github.com/serverless/serverless/blob/master/CONTRIBUTING.md
4. Fill out the whole template so we have a good overview on the issue
5. Do not remove any section of the template. If something is not applicable leave it empty but leave it in the Issue
6. Please follow the template, otherwise we'll have to ask you to update it
-->

# This is a Bug Report

## Description

- What went wrong?

Upgrading to `serverless@1.48.1` results in a Bluebird warning `a promise was created in a handler but was not returned from it`

- What did you expect should have happened?

No warning written to the console 😄 

- What was the config you used?

`NODE_ENV=development` triggers these warnings to be written to the console by Bluebird. I was also running locally with `serverless-offline`.

- What stacktrace or error message from your provider did you see?

```
(node:5687) Warning: a promise was created in a handler at domain.js:126:23 but was not returned from it, see http://goo.gl/rRqMUw
    at Function.Promise.attempt.Promise.try (/<redacted>/node_modules/bluebird/js/release/method.js:30:9)
```

Similar or dependent issues:

- No directly related issues

## Additional Data

- **_Serverless Framework Version you're using_**: `v1.48.1` and above
- **_Operating System_**: macOS Mojave 10.14.5
- **_Stack Trace_**: Shown above
- **_Provider Error messages_**:



Discussion:
Okay, after looking at [the warning from Bluebird](http://bluebirdjs.com/docs/warning-explanations.html#warning-a-promise-was-created-in-a-handler-but-was-not-returned-from-it) and taking a look at `bluebird/js/release/method.js:30:9` from the stacktrace, I was able to track this down to this function released in v1.48.1: https://github.com/serverless/serverless/pull/6410/files#diff-c6a9b60de5c074445c02ce6523318a45R83

Setting `"trackingDisabled": true,` in `~/.serverlessrc` (documented [here](https://serverless.com/framework/docs/providers/aws/cli-reference/slstats#disable-statistics-and-usage-tracking)) did the trick to remove the warning, but isn't really a viable approach.

EDIT:
I narrowed it down further to this call of `track()`: https://github.com/serverless/serverless/pull/6410/files#diff-fe2379480fbafcd9a7dd23866a045957R354

I'll open a PR to get this resolved.

Resolving patch:
diff --git a/lib/classes/Utils.js b/lib/classes/Utils.js
index 1140ee8bbe6..38a4a1e7d10 100644
--- a/lib/classes/Utils.js
+++ b/lib/classes/Utils.js
@@ -352,6 +352,8 @@ class Utils {
       return resolve(data);
     }).then(data => {
       if (data) tracking.track('segment', data);
+      // prevent Bluebird `Warning: a promise was created in a handler but was not returned from it` by returning null
+      return null;
     });
   }
 


Test patch:
diff --git a/lib/classes/Utils.test.js b/lib/classes/Utils.test.js
index 8db311a69cf..43ab87ed3b9 100644
--- a/lib/classes/Utils.test.js
+++ b/lib/classes/Utils.test.js
@@ -791,7 +791,8 @@ describe('Utils', () => {
         package: {},
       };
 
-      return expect(utils.logStat(serverless)).to.be.fulfilled.then(() => {
+      return expect(utils.logStat(serverless)).to.be.fulfilled.then(response => {
+        expect(response).to.be.null;
         expect(trackStub.calledOnce).to.equal(true);
         expect(getConfigStub.calledOnce).to.equal(true);