-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(cli): synthesis stops on expired AWS credentials
#21052 tried to fix the situation where we would keep on doing retries if AWS credentials were expired. However, this is now failing too hard for people that commonly have expired credentials in their environment but still want to have `cdk synth` complete successfully. Catch and swallow the error (but do complain with a warning) if we encounter an `ExpiredToken` during the `defaultAccount` operation. That's the only place where it's used, and the only place where the value is optional -- it behaves the same as if no credentials were configured. Also in this PR: add some TypeScript decorators to trace through a bunch of async method calls to come up with a reasonable trace of where errors originate. Not complete, not intended to be. But it is a nice basis for debugging SDK call behavior, and can be used more in the future.
- Loading branch information
Showing
7 changed files
with
100 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { debug } from '../logging'; | ||
|
||
let ENABLED = false; | ||
let INDENT = 0; | ||
|
||
export function enableTracing(enabled: boolean) { | ||
ENABLED = enabled; | ||
} | ||
|
||
/** | ||
* Method decorator to trace a single static or member method, any time it's called | ||
*/ | ||
export function traceCall(receiver: object, _propertyKey: string, descriptor: PropertyDescriptor, parentClassName?: string) { | ||
const fn = descriptor.value; | ||
const className = typeof receiver === 'function' ? receiver.name : parentClassName; | ||
|
||
descriptor.value = function (...args: any[]) { | ||
if (!ENABLED) { return fn.apply(this, args); } | ||
|
||
debug(`[trace] ${' '.repeat(INDENT)}${className || this.constructor.name || '(anonymous)'}#${fn.name}()`); | ||
INDENT += 2; | ||
|
||
const ret = fn.apply(this, args); | ||
if (ret instanceof Promise) { | ||
return ret.finally(() => { | ||
INDENT -= 2; | ||
}); | ||
} else { | ||
INDENT -= 2; | ||
return ret; | ||
} | ||
}; | ||
return descriptor; | ||
} | ||
|
||
/** | ||
* Class decorator, enable tracing for all methods on this class | ||
*/ | ||
export function traceMethods(constructor: Function) { | ||
// Statics | ||
for (const [name, descriptor] of Object.entries(Object.getOwnPropertyDescriptors(constructor))) { | ||
if (typeof descriptor.value !== 'function') { continue; } | ||
const newDescriptor = traceCall(constructor, name, descriptor, constructor.name) ?? descriptor; | ||
Object.defineProperty(constructor, name, newDescriptor); | ||
} | ||
|
||
// Instancne members | ||
for (const [name, descriptor] of Object.entries(Object.getOwnPropertyDescriptors(constructor.prototype))) { | ||
if (typeof descriptor.value !== 'function') { continue; } | ||
const newDescriptor = traceCall(constructor.prototype, name, descriptor, constructor.name) ?? descriptor; | ||
Object.defineProperty(constructor.prototype, name, newDescriptor); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters