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' ) ;
5
7
6
8
/**
7
9
* Represents a general toolkit error in the AWS CDK Toolkit.
@@ -40,19 +42,30 @@ export class ToolkitError extends Error {
40
42
*/
41
43
public readonly type : string ;
42
44
45
+ /**
46
+ * Denotes the source of the error as the toolkit.
47
+ */
48
+ public readonly source : 'toolkit' | 'user' ;
49
+
43
50
constructor ( message : string , type : string = 'toolkit' ) {
44
51
super ( message ) ;
45
52
Object . setPrototypeOf ( this , ToolkitError . prototype ) ;
46
53
Object . defineProperty ( this , TOOLKIT_ERROR_SYMBOL , { value : true } ) ;
47
54
this . name = new . target . name ;
48
55
this . type = type ;
56
+ this . source = 'toolkit' ;
49
57
}
50
58
}
51
59
52
60
/**
53
61
* Represents an authentication-specific error in the AWS CDK Toolkit.
54
62
*/
55
63
export class AuthenticationError extends ToolkitError {
64
+ /**
65
+ * Denotes the source of the error as user.
66
+ */
67
+ public readonly source = 'user' ;
68
+
56
69
constructor ( message : string ) {
57
70
super ( message , 'authentication' ) ;
58
71
Object . setPrototypeOf ( this , AuthenticationError . prototype ) ;
@@ -61,20 +74,61 @@ export class AuthenticationError extends ToolkitError {
61
74
}
62
75
63
76
/**
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.
65
80
*/
66
81
export class AssemblyError extends ToolkitError {
67
- constructor ( message : string ) {
82
+ /**
83
+ * An AssemblyError with an original error as cause
84
+ */
85
+ public static withCause ( message : string , error : unknown ) : AssemblyError {
86
+ return new AssemblyError ( message , undefined , error ) ;
87
+ }
88
+
89
+ /**
90
+ * An AssemblyError with a list of stacks as cause
91
+ */
92
+ public static withStacks ( 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 ) {
68
115
super ( message , 'assembly' ) ;
69
116
Object . setPrototypeOf ( this , AssemblyError . prototype ) ;
70
117
Object . defineProperty ( this , ASSEMBLY_ERROR_SYMBOL , { value : true } ) ;
118
+ this . stacks = stacks ;
119
+ this . cause = cause ;
71
120
}
72
121
}
73
122
74
123
/**
75
124
* Represents an error originating from a Context Provider
76
125
*/
77
126
export class ContextProviderError extends ToolkitError {
127
+ /**
128
+ * Denotes the source of the error as user.
129
+ */
130
+ public readonly source = 'user' ;
131
+
78
132
constructor ( message : string ) {
79
133
super ( message , 'context-provider' ) ;
80
134
Object . setPrototypeOf ( this , ContextProviderError . prototype ) ;
0 commit comments