Enable debug-mode "long stack traces" for Bluebird promises (async code)

Change-type: patch
Signed-off-by: Paulo Castro <paulo@balena.io>
This commit is contained in:
Paulo Castro 2019-10-30 15:25:05 +00:00
parent 09f04be77d
commit 2222a90884
2 changed files with 27 additions and 11 deletions

View File

@ -90,21 +90,34 @@ function setupBalenaSdkSharedOptions() {
});
}
export function globalInit() {
setupRaven();
checkNodeVersion();
setupGlobalHttpProxy();
setupBalenaSdkSharedOptions();
let BluebirdConfigured = false;
// Assign bluebird as the global promise library.
// stream-to-promise will produce native promises if not for this module,
// which is likely to lead to errors as much of the CLI coffeescript code
// expects bluebird promises.
// The registration is only run if it hasn't already happened (for example
// in a test case).
/**
* 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 CoffeeScript code expects Bluebird
* promises.
*/
export function configureBluebird() {
if (BluebirdConfigured) {
return;
}
BluebirdConfigured = true;
const Bluebird = require('bluebird');
Bluebird.config({
longStackTraces: process.env.DEBUG ? true : false,
});
if (!(global as any)['@@any-promise/REGISTRATION']) {
require('any-promise/register/bluebird');
}
}
export function globalInit() {
setupRaven();
checkNodeVersion();
configureBluebird();
setupGlobalHttpProxy();
setupBalenaSdkSharedOptions();
// check for CLI updates once a day
require('./utils/update').notify();

View File

@ -20,6 +20,9 @@ import * as nock from 'nock';
import * as path from 'path';
import * as balenaCLI from '../build/app';
import { configureBluebird } from '../build/app-common';
configureBluebird();
export const runCommand = async (cmd: string) => {
const preArgs = [process.argv[0], path.join(process.cwd(), 'bin', 'balena')];