File tree Expand file tree Collapse file tree 2 files changed +16
-1
lines changed
packages/backend-deployer/src Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ ' @aws-amplify/backend-deployer ' : patch
3
+ ---
4
+
5
+ truncate large error messages before printing to customer
Original file line number Diff line number Diff line change @@ -199,14 +199,24 @@ export class CDKDeployer implements BackendDeployer {
199
199
// However if the cdk process didn't run or produced no output, then we have nothing to go on with. So we throw
200
200
// this error to aid in some debugging.
201
201
if ( aggregatedStderr . trim ( ) ) {
202
+ // If the string is more than 65KB, truncate and keep the last portion.
202
203
// eslint-disable-next-line amplify-backend-rules/prefer-amplify-errors
203
- throw new Error ( aggregatedStderr ) ;
204
+ throw new Error ( this . truncateString ( aggregatedStderr , 65000 ) ) ;
204
205
} else {
205
206
throw error ;
206
207
}
207
208
}
208
209
} ;
209
210
211
+ private truncateString = ( str : string , size : number ) => {
212
+ const encoder = new TextEncoder ( ) ;
213
+ const decoder = new TextDecoder ( ) ;
214
+ const encoded = encoder . encode ( str ) ;
215
+ return encoded . byteLength > size
216
+ ? '...truncated...' + decoder . decode ( encoded . slice ( - size ) )
217
+ : str ;
218
+ } ;
219
+
210
220
private getAppCommand = ( ) =>
211
221
this . packageManagerController . getCommand ( [
212
222
'tsx' ,
You can’t perform that action at this time.
0 commit comments