mirror of
https://github.com/balena-io/balena-cli.git
synced 2024-12-19 13:47:52 +00:00
Merge pull request #1438 from balena-io/debug-to-stderr
Send all debug output to stderr
This commit is contained in:
commit
eac229ab7c
@ -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);
|
||||
}
|
||||
|
@ -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(
|
||||
|
@ -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);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -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
|
||||
}`,
|
||||
|
Loading…
Reference in New Issue
Block a user