Skip to content

Commit c863999

Browse files
authored
print stack traces in debug mode for sandbox deploy failures (#2799)
* print stack traces in debug mode for sandbox deploy failures * minor fixup * minor fixup * minor fixup
1 parent fada81d commit c863999

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

.changeset/metal-foxes-argue.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@aws-amplify/sandbox': patch
3+
---
4+
5+
print stack traces in debug mode for sandbox deploy failures

packages/sandbox/src/file_watching_sandbox.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,24 @@ void describe('Sandbox using local project name resolver', () => {
719719
mockEmit.mock.calls[1].arguments[0],
720720
'successfulDeployment',
721721
);
722+
723+
// assert print statements are called correctly
724+
assert.strictEqual(printer.log.mock.callCount(), 15);
725+
assert.match(
726+
printer.log.mock.calls[5].arguments[0],
727+
/random BackendDeployer error/,
728+
);
729+
assert.strictEqual(printer.log.mock.calls[5].arguments[1], LogLevel.ERROR);
730+
assert.strictEqual(
731+
printer.log.mock.calls[6].arguments[0],
732+
'Stack Trace for UnknownFault',
733+
);
734+
assert.strictEqual(printer.log.mock.calls[6].arguments[1], LogLevel.DEBUG);
735+
assert.match(
736+
printer.log.mock.calls[7].arguments[0],
737+
/file_watching_sandbox.ts/,
738+
);
739+
assert.strictEqual(printer.log.mock.calls[7].arguments[1], LogLevel.DEBUG);
722740
});
723741

724742
void it('handles UpdateNotSupported error while deploying and offers to reset sandbox and customer says yes', async (contextual) => {

packages/sandbox/src/file_watching_sandbox.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,27 @@ export class FileWatchingSandbox extends EventEmitter implements Sandbox {
343343
setSpanAttributes(span, data);
344344
span.end();
345345
// Print a meaningful message
346-
this.printer.log(format.error(error), LogLevel.ERROR);
346+
this.printer.log(format.error(amplifyError), LogLevel.ERROR);
347+
348+
// Print stack traces
349+
let errorToDisplayStackTrace: Error | undefined = amplifyError;
350+
while (errorToDisplayStackTrace) {
351+
if (errorToDisplayStackTrace.stack) {
352+
this.printer.log(
353+
`Stack Trace for ${errorToDisplayStackTrace.name}`,
354+
LogLevel.DEBUG,
355+
);
356+
this.printer.log(
357+
format.dim(errorToDisplayStackTrace.stack),
358+
LogLevel.DEBUG,
359+
);
360+
}
361+
errorToDisplayStackTrace =
362+
errorToDisplayStackTrace.cause instanceof Error
363+
? errorToDisplayStackTrace.cause
364+
: undefined;
365+
}
366+
347367
this.emit('failedDeployment', error);
348368

349369
// If the error is because of a non-allowed destructive change such as

0 commit comments

Comments
 (0)