From e87886e5565d72dde53ad91f6d42976a8f1c4ba9 Mon Sep 17 00:00:00 2001 From: Alan Ren Date: Wed, 13 Sep 2023 09:40:50 -0700 Subject: [PATCH] handle error scenarios for validity check (#24393) --- .../browser/modelComponents/componentBase.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/sql/workbench/browser/modelComponents/componentBase.ts b/src/sql/workbench/browser/modelComponents/componentBase.ts index 9941be42cd17..0eb3e23f8a3b 100644 --- a/src/sql/workbench/browser/modelComponents/componentBase.ts +++ b/src/sql/workbench/browser/modelComponents/componentBase.ts @@ -298,9 +298,16 @@ export abstract class ContainerBase { this.logService.debug(`Running container validation on component ${this.descriptor.id} to check validity of all child items`); return this.items.every(item => { - const valid = this.modelStore.getComponent(item.descriptor.id)?.valid; + const component = this.modelStore.getComponent(item.descriptor.id); + if (component === undefined) { + this.logService.warn(`Child item ${item.descriptor.id} of type ${item.descriptor.type} is undefined`); + } else if (component.valid === undefined) { + this.logService.warn(`The validity of child item ${item.descriptor.id} of type ${item.descriptor.type} undefined`); + } + // if the component is not found or the `valid` property is not set, we should treat it as valid. + const valid = component?.valid ?? true; this.logService.debug(`Child item ${item.descriptor.id} validity is ${valid}`); - return valid || false; + return valid; }); }); }