Skip to content

chore(core): Print docker stdout & stderr on error #23893

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/@aws-cdk/core/lib/private/asset-staging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ export function dockerExec(args: string[], options?: SpawnSyncOptions) {
});

if (proc.error) {
if (proc.stdout || proc.stderr) {
// eslint-disable-next-line no-console
console.log('[Process failed] stdout: %s\n\n\nstderr: %s', proc.stdout?.toString().trim(), proc.stderr?.toString().trim());
}
throw proc.error;
}

Expand Down
23 changes: 22 additions & 1 deletion packages/@aws-cdk/core/test/private/asset-staging.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as child_process from 'child_process';
import * as sinon from 'sinon';
import { AssetStaging, DockerImage } from '../../lib';
import { AssetBundlingBindMount, AssetBundlingVolumeCopy } from '../../lib/private/asset-staging';
import { AssetBundlingBindMount, AssetBundlingVolumeCopy, dockerExec } from '../../lib/private/asset-staging';

describe('bundling', () => {
afterEach(() => {
Expand Down Expand Up @@ -109,4 +109,25 @@ describe('bundling', () => {
'alpine',
]), { stdio: ['ignore', process.stderr, 'inherit'] })).toEqual(true);
});

test('fails when process failed', () => {
// GIVEN
sinon.stub(process, 'platform').value('darwin');
sinon.stub(child_process, 'spawnSync').returns({
status: null,
stderr: Buffer.from('stderr'),
stdout: Buffer.from('stdout'),
pid: 123,
output: ['stdout', 'stderr'],
signal: null,
error: new Error('something error'),
});
const logStub = sinon.stub(console, 'log');

// THEN
expect(() => dockerExec(['run', '--rm', '-v', 'alpine'], {})).toThrow(/something error/);
expect(logStub.calledWith('[Process failed] stdout: %s\n\n\nstderr: %s', 'stdout', 'stderr')).toEqual(true);

logStub.restore();
});
});