Enable long stack traces for --debug as well as DEBUG=1

Change-type: patch
This commit is contained in:
Pagan Gazzard 2020-07-01 00:27:21 +01:00 committed by Balena CI
parent 15ed67422d
commit f6ca5ef397
5 changed files with 8 additions and 30 deletions

View File

@ -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();

View File

@ -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];

View File

@ -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",

View File

@ -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?

View File

@ -15,10 +15,6 @@
* limitations under the License.
*/
import { configureBluebird } from '../build/app-common';
configureBluebird();
import * as nock from 'nock';
export interface ScopeOpts {