@@ -18,7 +18,6 @@ const EDGE_PORT = process.env.EDGE_PORT || DEFAULT_EDGE_PORT;
1818const DEFAULT_HOSTNAME = "localhost" ;
1919const LAMBDA_MOUNT_CODE = isEnvTrue ( "LAMBDA_MOUNT_CODE" ) ;
2020const PROTOCOL = isEnvTrue ( "USE_SSL" ) ? "https" : "http" ;
21- const DEBUG_ON = process . env . DEBUG === "1" ;
2221
2322
2423//----------------
@@ -29,6 +28,14 @@ const getLocalEndpoint = async () => process.env.AWS_ENDPOINT_URL || `${PROTOCOL
2928
3029var resolvedHostname = undefined ;
3130
31+ const runAsyncFunctionAsSync = ( asyncFn ) => {
32+ return ( ...args ) => {
33+ asyncFn ( ...args ) . catch ( ( e ) => {
34+ console . error ( e ) ;
35+ } ) ;
36+ } ;
37+ } ;
38+
3239const getLocalHost = async ( ) => {
3340 if ( resolvedHostname ) {
3441 // early exit to not resolve again
@@ -207,10 +214,6 @@ const patchCurrentAccount = (SDK) => {
207214const patchToolkitInfo = ( ToolkitInfo ) => {
208215 const setBucketUrl = function setBucketUrl ( object , bucket , domain ) {
209216 const newBucketUrl = `https://${ domain . replace ( `${ bucket } .` , "" ) } :${ EDGE_PORT } /${ bucket } ` ;
210- if ( DEBUG_ON ) {
211- console . debug ( "Old bucketUrl:" , object . bucketUrl ) ;
212- console . debug ( "New bucketUrl:" , newBucketUrl ) ;
213- }
214217 Object . defineProperty ( object , "bucketUrl" , {
215218 get ( ) {
216219 return newBucketUrl ;
@@ -221,7 +224,7 @@ const patchToolkitInfo = (ToolkitInfo) => {
221224 // Pre-fetch the necessary values for the bucket URL
222225 const prefetchBucketUrl = async ( object ) => {
223226 // Has been observed that the object is not always an instance of ToolkitInfo
224- if ( object != { } ) {
227+ if ( object && Object . prototype . hasOwnProperty . call ( object , "bucketName" ) && Object . prototype . hasOwnProperty . call ( object , "bucketUrl" ) ) {
225228 try {
226229 const bucket = object . bucketName ;
227230 const domain = object . bucketUrl . replace ( "https://" , "" ) || await getLocalHost ( ) ;
@@ -241,7 +244,7 @@ const patchToolkitInfo = (ToolkitInfo) => {
241244 } ;
242245
243246 // for compatibility with with older versions of CDK
244- prefetchBucketUrl ( ToolkitInfo . prototype ) ;
247+ runAsyncFunctionAsSync ( prefetchBucketUrl ( ToolkitInfo . prototype ) ) ;
245248
246249 const cdkLookupFn = ToolkitInfo . lookup ;
247250 ToolkitInfo . lookup = async ( ...args ) => {
@@ -253,7 +256,7 @@ const patchToolkitInfo = (ToolkitInfo) => {
253256 const fromStackFn = ToolkitInfo . fromStack ;
254257 ToolkitInfo . fromStack = ( ...args ) => {
255258 const toolkitInfoObject = fromStackFn ( ...args ) ;
256- prefetchBucketUrl ( toolkitInfoObject ) ;
259+ runAsyncFunctionAsSync ( prefetchBucketUrl ( toolkitInfoObject ) ) ;
257260 return toolkitInfoObject ;
258261 } ;
259262} ;
0 commit comments