Merge pull request #1438 from balena-io/debug-to-stderr

Send all debug output to stderr
This commit is contained in:
CameronDiver 2019-09-23 09:45:53 +01:00 committed by GitHub
commit eac229ab7c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 6 deletions

View File

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

View File

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

View File

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

View File

@ -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
}`,