1- const TOOLKIT_ERROR_SYMBOL = Symbol . for ( '@aws-cdk/toolkit.ToolkitError' ) ;
2- const AUTHENTICATION_ERROR_SYMBOL = Symbol . for ( '@aws-cdk/toolkit.AuthenticationError' ) ;
3- const ASSEMBLY_ERROR_SYMBOL = Symbol . for ( '@aws-cdk/toolkit.AssemblyError' ) ;
4- const CONTEXT_PROVIDER_ERROR_SYMBOL = Symbol . for ( '@aws-cdk/toolkit.ContextProviderError' ) ;
1+ import type * as cxapi from '@aws-cdk/cx-api' ;
2+
3+ const TOOLKIT_ERROR_SYMBOL = Symbol . for ( '@aws-cdk/toolkit-lib.ToolkitError' ) ;
4+ const AUTHENTICATION_ERROR_SYMBOL = Symbol . for ( '@aws-cdk/toolkit-lib.AuthenticationError' ) ;
5+ const ASSEMBLY_ERROR_SYMBOL = Symbol . for ( '@aws-cdk/toolkit-lib.AssemblyError' ) ;
6+ const CONTEXT_PROVIDER_ERROR_SYMBOL = Symbol . for ( '@aws-cdk/toolkit-lib.ContextProviderError' ) ;
57
68/**
79 * Represents a general toolkit error in the AWS CDK Toolkit.
@@ -40,19 +42,30 @@ export class ToolkitError extends Error {
4042 */
4143 public readonly type : string ;
4244
45+ /**
46+ * Denotes the source of the error as the toolkit.
47+ */
48+ public readonly source : 'toolkit' | 'user' ;
49+
4350 constructor ( message : string , type : string = 'toolkit' ) {
4451 super ( message ) ;
4552 Object . setPrototypeOf ( this , ToolkitError . prototype ) ;
4653 Object . defineProperty ( this , TOOLKIT_ERROR_SYMBOL , { value : true } ) ;
4754 this . name = new . target . name ;
4855 this . type = type ;
56+ this . source = 'toolkit' ;
4957 }
5058}
5159
5260/**
5361 * Represents an authentication-specific error in the AWS CDK Toolkit.
5462 */
5563export class AuthenticationError extends ToolkitError {
64+ /**
65+ * Denotes the source of the error as user.
66+ */
67+ public readonly source = 'user' ;
68+
5669 constructor ( message : string ) {
5770 super ( message , 'authentication' ) ;
5871 Object . setPrototypeOf ( this , AuthenticationError . prototype ) ;
@@ -61,20 +74,61 @@ export class AuthenticationError extends ToolkitError {
6174}
6275
6376/**
64- * Represents an authentication-specific error in the AWS CDK Toolkit.
77+ * Represents an error causes by cloud assembly synthesis
78+ *
79+ * This includes errors thrown during app execution, as well as failing annotations.
6580 */
6681export class AssemblyError extends ToolkitError {
67- constructor ( message : string ) {
82+ /**
83+ * An AssemblyError with an original error as cause
84+ */
85+ public static fromCause ( message : string , error : unknown , stacks ?: cxapi . CloudFormationStackArtifact [ ] ) : AssemblyError {
86+ return new AssemblyError ( message , stacks , error ) ;
87+ }
88+
89+ /**
90+ * An AssemblyError with a list of stacks as cause
91+ */
92+ public static fromStacks ( message : string , stacks ?: cxapi . CloudFormationStackArtifact [ ] ) : AssemblyError {
93+ return new AssemblyError ( message , stacks ) ;
94+ }
95+
96+ /**
97+ * Denotes the source of the error as user.
98+ */
99+ public readonly source = 'user' ;
100+
101+ /**
102+ * The stacks that caused the error, if available
103+ *
104+ * The `messages` property of each `cxapi.CloudFormationStackArtifact` will contain the respective errors.
105+ * Absence indicates synthesis didn't fully complete.
106+ */
107+ public readonly stacks ?: cxapi . CloudFormationStackArtifact [ ] ;
108+
109+ /**
110+ * The specific original cause of the error, if available
111+ */
112+ public readonly cause ?: unknown ;
113+
114+ private constructor ( message : string , stacks ?: cxapi . CloudFormationStackArtifact [ ] , cause ?: unknown ) {
68115 super ( message , 'assembly' ) ;
69116 Object . setPrototypeOf ( this , AssemblyError . prototype ) ;
70117 Object . defineProperty ( this , ASSEMBLY_ERROR_SYMBOL , { value : true } ) ;
118+ this . stacks = stacks ;
119+ this . cause = cause ;
71120 }
72121}
73122
74123/**
75124 * Represents an error originating from a Context Provider
76125 */
77126export class ContextProviderError extends ToolkitError {
127+ /**
128+ * Denotes the source of the error as user.
129+ */
130+ public readonly source = 'user' ;
131+
78132 constructor ( message : string ) {
79133 super ( message , 'context-provider' ) ;
80134 Object . setPrototypeOf ( this , ContextProviderError . prototype ) ;
0 commit comments