File tree Expand file tree Collapse file tree 5 files changed +18
-8
lines changed Expand file tree Collapse file tree 5 files changed +18
-8
lines changed Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ export class AmplifyPrinter implements Printer {
19
19
// (undocumented)
20
20
debug: (line : string ) => void ;
21
21
// (undocumented)
22
- error: (line : string ) => void ;
22
+ error: (line : string , error ? : any ) => void ;
23
23
// Warning: (ae-forgotten-export) The symbol "Color" needs to be exported by the entry point index.d.ts
24
24
//
25
25
// (undocumented)
@@ -180,7 +180,7 @@ export type Printer = {
180
180
blankLine: () => void ;
181
181
success: (line : string ) => void ;
182
182
warn: (line : string ) => void ;
183
- error: (line : string ) => void ;
183
+ error: (line : string , error ? : any ) => void ;
184
184
};
185
185
186
186
// @public (undocumented)
Original file line number Diff line number Diff line change @@ -81,3 +81,9 @@ it('prints error line when silent flag is set', () => {
81
81
printer . error ( testInput ) ;
82
82
expect ( writeStream_stub . write . mock . calls [ 0 ] [ 0 ] . trim ( ) ) . toMatchInlineSnapshot ( `"🛑 [31mthis is a test line[39m"` ) ;
83
83
} ) ;
84
+
85
+ it ( 'prints error message when the error is an object' , ( ) => {
86
+ printer . error ( '' , new Error ( testInput ) ) ;
87
+
88
+ expect ( writeStream_stub . write . mock . calls [ 1 ] [ 0 ] . trim ( ) ) . toMatchInlineSnapshot ( `"[31mthis is a test line[39m"` ) ;
89
+ } ) ;
Original file line number Diff line number Diff line change @@ -30,8 +30,13 @@ export class AmplifyPrinter implements Printer {
30
30
this . writeLine ( `${ isHeadless ? '' : '⚠️ ' } ${ chalk . yellow ( line ) } ` ) ;
31
31
} ;
32
32
33
- error = ( line : string ) : void => {
33
+ // disable-eslint-next-line @typescript-eslint/no-explicit-any
34
+ error = ( line : string , error ?: any ) : void => {
34
35
this . writeLine ( `${ isHeadless ? '' : '🛑 ' } ${ chalk . red ( line ) } ` ) ;
36
+ const errorMessage = error ?. message ?? error ;
37
+ if ( errorMessage ) {
38
+ this . writeLine ( `${ chalk . red ( errorMessage ) } ` ) ;
39
+ }
35
40
} ;
36
41
37
42
private writeSilenceableLine = ( line ?: string ) : void => {
@@ -59,7 +64,7 @@ export type Printer = {
59
64
blankLine : ( ) => void ;
60
65
success : ( line : string ) => void ;
61
66
warn : ( line : string ) => void ;
62
- error : ( line : string ) => void ;
67
+ error : ( line : string , error ?: any ) => void ;
63
68
} ;
64
69
65
70
type Color = 'green' | 'blue' | 'yellow' | 'red' | 'reset' ;
Original file line number Diff line number Diff line change @@ -66,14 +66,14 @@ describe('function start', () => {
66
66
prompter_mock . pick . mockResolvedValue ( [ 'funcName' ] ) ;
67
67
await start ( context_stub ) ;
68
68
expect ( printer_mock . error . mock . calls [ 0 ] [ 0 ] ) . toMatchInlineSnapshot ( `"funcName failed with the following error:"` ) ;
69
- expect ( printer_mock . info . mock . calls [ 2 ] [ 0 ] ) . toMatchSnapshot ( ) ;
69
+ expect ( printer_mock . error . mock . calls [ 0 ] [ 1 ] ) . toMatchSnapshot ( ) ;
70
70
context_stub . input . options . timeout = 1 ;
71
71
} ) ;
72
72
73
73
it ( 'times out function execution at the specified time' , async ( ) => {
74
74
getInvoker_mock . mockResolvedValueOnce ( ( ) => new Promise ( ( resolve ) => setTimeout ( ( ) => resolve ( 'lambda value' ) , 2000 ) ) ) ;
75
75
await start ( context_stub ) ;
76
- expect ( printer_mock . info . mock . calls [ 2 ] [ 0 ] ) . toMatchSnapshot ( ) ;
76
+ expect ( printer_mock . error . mock . calls [ 0 ] [ 1 ] ) . toMatchSnapshot ( ) ;
77
77
} ) ;
78
78
79
79
it ( 'triggers a dev build before invoking' , async ( ) => {
Original file line number Diff line number Diff line change @@ -57,8 +57,7 @@ export async function start(context: $TSContext): Promise<void> {
57
57
printer . success ( 'Result:' ) ;
58
58
printer . info ( typeof result === 'undefined' ? '' : stringResult ) ;
59
59
} catch ( err ) {
60
- printer . error ( `${ resourceName } failed with the following error:` ) ;
61
- printer . info ( err ) ;
60
+ printer . error ( `${ resourceName } failed with the following error:` , err ) ;
62
61
} finally {
63
62
printer . info ( 'Finished execution.' ) ;
64
63
}
You can’t perform that action at this time.
0 commit comments