-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
45 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,54 @@ | ||
import { ToolkitError } from '../../errors'; | ||
import { IoMessageCode } from '../io-message'; | ||
|
||
export const CODES = { | ||
// Default codes -- all 0000 codes | ||
CDK_TOOLKIT_I0000: 'Default toolkit info code', | ||
CDK_TOOLKIT_E0000: 'Default toolkit error code', | ||
CDK_TOOLKIT_WOOOO: 'Default toolkit warning code', | ||
CDK_SDK_I0000: 'Default sdk info code', | ||
CDK_SDK_E0000: 'Default sdk error code', | ||
CDK_SDK_WOOOO: 'Default sdk warning code', | ||
CDK_ASSETS_I0000: 'Default assets info code', | ||
CDK_ASSETS_E0000: 'Default assets error code', | ||
CDK_ASSETS_WOOOO: 'Default assets warning code', | ||
CDK_ASSEMBLY_I0000: 'Default assembly info code', | ||
CDK_ASSEMBLY_E0000: 'Default assembly error code', | ||
CDK_ASSEMBLY_WOOOO: 'Default assembly warning code', | ||
|
||
// Toolkit Info codes | ||
CDK_TOOLKIT_I0001: 'Display stack data', | ||
CDK_TOOLKIT_I0002: 'Successfully deployed stacks', | ||
CDK_TOOLKIT_I5001: 'Display synthesis times', | ||
CDK_TOOLKIT_I5050: 'Confirm rollback', | ||
CDK_TOOLKIT_I5060: 'Confirm deploy security sensitive changes', | ||
CDK_TOOLKIT_I7010: 'Confirm destroy stacks', | ||
|
||
// Toolkit Warning codes | ||
|
||
// Toolkit Error codes | ||
|
||
// Assembly Info codes | ||
CDK_ASSEMBLY_I0042: 'Writing updated context', | ||
CDK_ASSEMBLY_I0241: 'Fetching missing context', | ||
|
||
// Assembly Warning codes | ||
|
||
// Assembly Error codes | ||
CDK_ASSEMBLY_E1111: 'Incompatible CDK CLI version. Upgrade needed.', | ||
}; | ||
|
||
// If we give CODES a type with key: IoMessageCode, | ||
// this dynamically generated type will generalize to allow all IoMessageCodes. | ||
// Instead, we will validate that VALID_CODE must be IoMessageCode with the '&'. | ||
export type VALID_CODE = keyof typeof CODES & IoMessageCode; | ||
|
||
/** | ||
* Verifies that the input is a valid code, and returns a ToolkitError if not. | ||
*/ | ||
export function isValidCode(code: IoMessageCode): VALID_CODE { | ||
if (code in CODES) { | ||
return code as VALID_CODE; | ||
} | ||
throw new ToolkitError(`Invalid message code: ${code}`); | ||
} |
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