From 7a865b2e151f54a0edf37c1884e362fc155214a3 Mon Sep 17 00:00:00 2001 From: Cameron Diver Date: Wed, 18 Sep 2019 13:13:35 +0100 Subject: [PATCH] Send all debug output to stderr Change-type: patch Signed-off-by: Cameron Diver --- automation/build-bin.ts | 14 +++++++++++++- lib/actions/push.ts | 2 +- lib/utils/logger.ts | 4 +++- lib/utils/remote-build.ts | 6 +++--- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/automation/build-bin.ts b/automation/build-bin.ts index f5d6149f..5c2716bc 100644 --- a/automation/build-bin.ts +++ b/automation/build-bin.ts @@ -22,6 +22,7 @@ import { execFile, spawn } from 'child_process'; import { stripIndent } from 'common-tags'; import * as filehound from 'filehound'; import * as fs from 'fs-extra'; +import * as _ from 'lodash'; import * as path from 'path'; import { exec as execPkg } from 'pkg'; import * as rimraf from 'rimraf'; @@ -348,7 +349,18 @@ async function getSubprocessStdout( child.stderr.on('data', (data: Buffer) => { try { const stderr = data.toString(); - reject(new Error(`"${execPath}": non-empty stderr "${stderr}"`)); + + // ignore any debug lines, but ensure that we parse + // every line provided to the stderr stream + const lines = _.filter( + stderr.trim().split(/\r?\n/), + line => !line.startsWith('[debug]'), + ); + if (lines.length > 0) { + reject( + new Error(`"${execPath}": non-empty stderr "${lines.join('\n')}"`), + ); + } } catch (err) { reject(err); } diff --git a/lib/actions/push.ts b/lib/actions/push.ts index 3973d362..cd8eb950 100644 --- a/lib/actions/push.ts +++ b/lib/actions/push.ts @@ -268,7 +268,7 @@ export const push: CommandDefinition< const source = options.source || '.'; if (process.env.DEBUG) { - console.log(`[debug] Using ${source} as build source`); + console.error(`[debug] Using ${source} as build source`); } const dockerfilePath = validateSpecifiedDockerfile( diff --git a/lib/utils/logger.ts b/lib/utils/logger.ts index a5fc54dd..b8005dc3 100644 --- a/lib/utils/logger.ts +++ b/lib/utils/logger.ts @@ -63,8 +63,10 @@ class Logger { }; _.forEach(this.streams, function(stream, key) { - if (key !== 'debug' || process.env.DEBUG) { + if (key !== 'debug') { stream.pipe(process.stdout); + } else if (process.env.DEBUG) { + stream.pipe(process.stderr); } }); diff --git a/lib/utils/remote-build.ts b/lib/utils/remote-build.ts index c6879502..a22531e4 100644 --- a/lib/utils/remote-build.ts +++ b/lib/utils/remote-build.ts @@ -222,7 +222,7 @@ function getBuilderMessageHandler( ): (obj: BuilderMessage) => void { return (obj: BuilderMessage) => { if (DEBUG_MODE) { - console.log(`[debug] handling message: ${JSON.stringify(obj)}`); + console.error(`[debug] handling message: ${JSON.stringify(obj)}`); } if (obj.type != null && obj.type === 'metadata') { return handleBuilderMetadata(obj, build); @@ -318,7 +318,7 @@ function createRemoteBuildRequest( ): request.Request { const zlib = require('zlib'); if (DEBUG_MODE) { - console.log(`[debug] Connecting to builder at ${builderUrl}`); + console.error(`[debug] Connecting to builder at ${builderUrl}`); } return request .post({ @@ -331,7 +331,7 @@ function createRemoteBuildRequest( .once('response', (response: request.RequestResponse) => { if (response.statusCode >= 100 && response.statusCode < 400) { if (DEBUG_MODE) { - console.log( + console.error( `[debug] received HTTP ${response.statusCode} ${ response.statusMessage }`,