From fb3d3334539c5581869e02cb5953dd5f854a98c1 Mon Sep 17 00:00:00 2001 From: Prabhat Khera <91852476+prabhat-org@users.noreply.github.com> Date: Tue, 2 Aug 2022 14:39:53 +1200 Subject: [PATCH] fix(registries): Cannot read properties of null error on change of namespace EE-3747 (#7363) --- .../imageRegistry/por-image-registry.controller.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/app/docker/components/imageRegistry/por-image-registry.controller.js b/app/docker/components/imageRegistry/por-image-registry.controller.js index 5bbaa0ece..8d4a9c6ef 100644 --- a/app/docker/components/imageRegistry/por-image-registry.controller.js +++ b/app/docker/components/imageRegistry/por-image-registry.controller.js @@ -26,10 +26,13 @@ class porImageRegistryController { } isKnownRegistry(registry) { - return !(registry instanceof DockerHubViewModel) && registry.URL; + return registry && !(registry instanceof DockerHubViewModel) && registry.URL; } getRegistryURL(registry) { + if (!registry) { + return; + } let url = registry.URL; if (registry.Type === RegistryTypes.GITLAB) { url = registry.URL + '/' + registry.Gitlab.ProjectPath; @@ -54,12 +57,12 @@ class porImageRegistryController { } isDockerHubRegistry() { - return this.model.UseRegistry && (this.model.Registry.Type === RegistryTypes.DOCKERHUB || this.model.Registry.Type === RegistryTypes.ANONYMOUS); + return this.model.UseRegistry && this.model.Registry && (this.model.Registry.Type === RegistryTypes.DOCKERHUB || this.model.Registry.Type === RegistryTypes.ANONYMOUS); } async onRegistryChange() { this.prepareAutocomplete(); - if (this.model.Registry.Type === RegistryTypes.GITLAB && this.model.Image) { + if (this.model.Registry && this.model.Registry.Type === RegistryTypes.GITLAB && this.model.Image) { this.model.Image = _.replace(this.model.Image, this.model.Registry.Gitlab.ProjectPath, ''); } } @@ -71,7 +74,7 @@ class porImageRegistryController { } displayedRegistryURL() { - return this.getRegistryURL(this.model.Registry) || 'docker.io'; + return (this.model.Registry && this.getRegistryURL(this.model.Registry)) || 'docker.io'; } async reloadRegistries() { @@ -90,7 +93,7 @@ class porImageRegistryController { this.registries.splice(0, 0, this.defaultRegistry); } - const id = this.model.Registry.Id; + const id = this.model.Registry && this.model.Registry.Id; const registry = _.find(this.registries, { Id: id }); if (!registry) { this.model.Registry = showDefaultRegistry ? this.defaultRegistry : this.registries[0];