Skip to content

Commit b306941

Browse files
authored
feat: show an accurate description for Constructs in validation errors (#1110)
Until now, validation errors would only show the underlying base type of the construct. Many Constructs share the same base type, which makes it hard to tell them apart. Now, each Construct implements a `describe()` method which returns a unique description for the Construct instance. It consists of the Construct class name and the logicalId of the instance.
1 parent 8d82c7b commit b306941

32 files changed

Lines changed: 134 additions & 1 deletion

packages/cli/src/constructs/alert-channel-subscription.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ export class AlertChannelSubscription extends Construct {
4848
Session.registerConstruct(this)
4949
}
5050

51+
describe (): string {
52+
return `AlertChannelSubscription:${this.logicalId}`
53+
}
54+
5155
synthesize () {
5256
return {
5357
alertChannelId: this.alertChannelId,

packages/cli/src/constructs/alert-channel.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ export class AlertChannelRef extends Construct {
7777
Session.registerConstruct(this)
7878
}
7979

80+
describe (): string {
81+
return `AlertChannelRef:${this.logicalId}`
82+
}
83+
8084
synthesize () {
8185
return null
8286
}

packages/cli/src/constructs/api-check.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,10 @@ export class ApiCheck extends RuntimeCheck {
231231
this.addPrivateLocationCheckAssignments()
232232
}
233233

234+
describe (): string {
235+
return `ApiCheck:${this.logicalId}`
236+
}
237+
234238
async validate (diagnostics: Diagnostics): Promise<void> {
235239
if (this.setupScript) {
236240
if (!isEntrypoint(this.setupScript) && !isContent(this.setupScript)) {

packages/cli/src/constructs/browser-check.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ export class BrowserCheck extends RuntimeCheck {
102102
this.addPrivateLocationCheckAssignments()
103103
}
104104

105+
describe (): string {
106+
return `BrowserCheck:${this.logicalId}`
107+
}
108+
105109
protected configDefaultsGetter (props: CheckProps): ConfigDefaultsGetter {
106110
return makeConfigDefaultsGetter(
107111
props.group?.getBrowserCheckDefaults(),

packages/cli/src/constructs/check-group-ref.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ export class CheckGroupRef extends Construct {
1414
Session.registerConstruct(this)
1515
}
1616

17+
describe (): string {
18+
return `CheckGroupRef:${this.logicalId}`
19+
}
20+
1721
public getCheckDefaults (): CheckConfigDefaults {
1822
// The only value CheckGroup.getCheckDefaults() returns is frequency,
1923
// which exists purely for convenience, and only at CLI-level. It never

packages/cli/src/constructs/check-group-v1.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,10 @@ export class CheckGroupV1 extends Construct {
350350
this.__addPrivateLocationGroupAssignments()
351351
}
352352

353+
describe (): string {
354+
return `CheckGroupV1:${this.logicalId}`
355+
}
356+
353357
protected async onBeforeValidate (diagnostics: Diagnostics): Promise<void> {
354358
diagnostics.add(new DeprecatedConstructDiagnostic(
355359
'CheckGroup',

packages/cli/src/constructs/check-group-v2.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ export class CheckGroupV2 extends CheckGroupV1 {
146146
this.useGlobalAlertSettings = useGlobalAlertSettings
147147
}
148148

149+
describe (): string {
150+
return `CheckGroupV2:${this.logicalId}`
151+
}
152+
149153
// eslint-disable-next-line @typescript-eslint/no-unused-vars
150154
async onBeforeValidate (diagnostics: Diagnostics): Promise<void> {
151155
// No-op

packages/cli/src/constructs/construct-diagnostics.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export class ConstructDiagnostic extends Diagnostic {
8989

9090
constructor (construct: Construct, underlying: Diagnostic) {
9191
super({
92-
title: `[${construct.type}:${construct.logicalId}] ${underlying.title}`,
92+
title: `[${construct.describe()}] ${underlying.title}`,
9393
message: underlying.message,
9494
})
9595

packages/cli/src/constructs/construct.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ export abstract class Construct implements Validate, Bundle {
7272
Session.validateCreateConstruct(this)
7373
}
7474

75+
/**
76+
* @returns A unique description of the Construct instance.
77+
*/
78+
abstract describe (): string
79+
7580
/**
7681
* Creates a reference to this construct that can be used in other constructs.
7782
*

packages/cli/src/constructs/dashboard.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,10 @@ export class Dashboard extends Construct {
273273
Session.registerConstruct(this)
274274
}
275275

276+
describe (): string {
277+
return `Dashboard:${this.logicalId}`
278+
}
279+
276280
async validate (diagnostics: Diagnostics): Promise<void> {
277281
if (!this.customUrl && !this.customDomain) {
278282
diagnostics.add(new InvalidPropertyValueDiagnostic(

0 commit comments

Comments
 (0)