From f6ca5ef3978e59739f9b5d9368921791fa67933b Mon Sep 17 00:00:00 2001 From: Pagan Gazzard Date: Wed, 1 Jul 2020 00:27:21 +0100 Subject: [PATCH] Enable long stack traces for `--debug` as well as `DEBUG=1` Change-type: patch --- lib/app-common.ts | 23 ----------------------- lib/preparser.ts | 7 +++++++ package.json | 1 - tests/config-tests.ts | 3 +-- tests/nock-mock.ts | 4 ---- 5 files changed, 8 insertions(+), 30 deletions(-) diff --git a/lib/app-common.ts b/lib/app-common.ts index 356a8c9e..2ae011d4 100644 --- a/lib/app-common.ts +++ b/lib/app-common.ts @@ -218,28 +218,6 @@ function setupBalenaSdkSharedOptions(settings: CliSettings) { }); } -let BluebirdConfigured = false; - -/** - * Configure Bluebird and assign it as the global promise library. - * Modules like `stream-to-promise` will otherwise produce native promises, - * which leads to errors as much of the CLI JavaScript code expects Bluebird - * promises. - */ -export function configureBluebird() { - if (BluebirdConfigured) { - return; - } - BluebirdConfigured = true; - const Bluebird = require('bluebird') as typeof import('bluebird'); - Bluebird.config({ - longStackTraces: process.env.DEBUG ? true : false, - }); - if (!(global as any)['@@any-promise/REGISTRATION']) { - require('any-promise/register/bluebird'); - } -} - /** * Addresses the console warning: * (node:49500) MaxListenersExceededWarning: Possible EventEmitter memory @@ -253,7 +231,6 @@ export function setMaxListeners(maxListeners: number) { export async function globalInit() { await setupSentry(); checkNodeVersion(); - configureBluebird(); const settings = new CliSettings(); diff --git a/lib/preparser.ts b/lib/preparser.ts index 1a45b68c..a6d4d018 100644 --- a/lib/preparser.ts +++ b/lib/preparser.ts @@ -61,6 +61,13 @@ export async function routeCliFramework(argv: string[], options: AppOptions) { } } + // Enable bluebird long stack traces when in debug mode, must be set + // before the first bluebird require - done here so that it will also + // be enabled when using the `--debug` flag to enable debug mode + if (process.env.DEBUG) { + process.env.BLUEBIRD_LONG_STACK_TRACES = '1'; + } + const Logger = await import('./utils/logger'); Logger.command = cmdSlice[0]; diff --git a/package.json b/package.json index 9549bd52..65f360d1 100644 --- a/package.json +++ b/package.json @@ -185,7 +185,6 @@ "@types/update-notifier": "^4.1.0", "@zeit/dockerignore": "0.0.3", "JSONStream": "^1.0.3", - "any-promise": "^1.3.0", "archiver": "^3.1.1", "balena-config-json": "^4.0.0", "balena-device-init": "^5.0.2", diff --git a/tests/config-tests.ts b/tests/config-tests.ts index 49085055..cb31e7c8 100644 --- a/tests/config-tests.ts +++ b/tests/config-tests.ts @@ -15,9 +15,8 @@ * limitations under the License. */ -import { configureBluebird, setMaxListeners } from '../build/app-common'; +import { setMaxListeners } from '../build/app-common'; -configureBluebird(); setMaxListeners(35); // it appears that 'nock' adds a bunch of listeners - bug? // SL: Looks like it's not nock causing this, as have seen the problem triggered from help.spec, // which is not using nock. Perhaps mocha/chai? (unlikely), or something in the CLI? diff --git a/tests/nock-mock.ts b/tests/nock-mock.ts index 07a212c9..87bcb1ba 100644 --- a/tests/nock-mock.ts +++ b/tests/nock-mock.ts @@ -15,10 +15,6 @@ * limitations under the License. */ -import { configureBluebird } from '../build/app-common'; - -configureBluebird(); - import * as nock from 'nock'; export interface ScopeOpts {