Skip to content

Commit 4d9bd6a

Browse files
committed
An error appears when validating a local K8s resource
``` stack trace: TypeError: Cannot read properties of undefined (reading 'metadata') at K8sResourceCache.<anonymous> (./vscode-openshift-tools/out/src/k8s/vfs/kuberesources.utils.js:226:49) at Generator.next (<anonymous>) at fulfilled (./vscode-openshift-tools/out/src/k8s/vfs/kuberesources.utils.js:42:58) ``` Signed-off-by: Victor Rubezhny <vrubezhny@redhat.com>
1 parent d5deea2 commit 4d9bd6a

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

src/k8s/vfs/kuberesources.utils.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,11 @@ export class K8sResourceCache {
190190
return [];
191191
}
192192

193-
const errors: Diagnostic[] = [];
194193
const cachedResource: K8sResource = this.get(uri)?.resource;
194+
if (!cachedResource) { // Nothing to validate against - skip
195+
return [];
196+
}
197+
195198
const resourceName = cachedResource.metadata.name;
196199
const namespace = cachedResource.metadata.namespace || 'default';
197200
const kind = cachedResource.kind.toLowerCase();
@@ -203,6 +206,7 @@ export class K8sResourceCache {
203206
`The field "${fieldPath.join('.')}" cannot be changed after the resource has been created. ` +
204207
'Kubernetes does not allow updates to immutable fields such as apiVersion, kind, metadata.name, or metadata.namespace.');
205208
const nullRange = new Range(textDocument.positionAt(0), textDocument.positionAt(0));
209+
const errors: Diagnostic[] = [];
206210

207211
// Validate whether the K8s resource is the same (kine/apiVersion/name/namespace)
208212
if (!this.isSameKind(cachedResource, resource)) {

0 commit comments

Comments
 (0)