{"record":{"id":"542b6460222a4131","repo":"goharbor/harbor","slug":"the-name-of-namespace-cannot-be-null-542b64","errorCode":null,"errorMessage":"the name of namespace cannot be null","messagePattern":"the name of namespace cannot be null","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/pkg/reg/adapter/jfrog/adapter.go","lineNumber":129,"sourceCode":"\t\tclient:   newClient(registry),\n\t}, nil\n}\n\n// PrepareForPush creates local docker repository in jfrog artifactory\nfunc (a *adapter) PrepareForPush(resources []*model.Resource) error {\n\tvar namespaces []string\n\tfor _, resource := range resources {\n\t\tif resource == nil {\n\t\t\treturn errors.New(\"the resource cannot be null\")\n\t\t}\n\t\tif resource.Metadata == nil {\n\t\t\treturn errors.New(\"the metadata of resource cannot be null\")\n\t\t}\n\t\tif resource.Metadata.Repository == nil {\n\t\t\treturn errors.New(\"the namespace of resource cannot be null\")\n\t\t}\n\t\tif len(resource.Metadata.Repository.Name) == 0 {\n\t\t\treturn errors.New(\"the name of namespace cannot be null\")\n\t\t}\n\t\tpath := strings.Split(resource.Metadata.Repository.Name, \"/\")\n\t\tif len(path) > 0 {\n\t\t\tnamespaces = append(namespaces, path[0])\n\t\t}\n\t}\n\n\trepositories, err := a.listAllRepositories()\n\tif err != nil {\n\t\treturn err\n\t}\n\texistedRepositories := make(map[string]struct{})\n\tfor _, repo := range repositories {\n\t\texistedRepositories[repo.Key] = struct{}{}\n\t}\n\n\tfor _, namespace := range namespaces {\n\t\tif _, ok := existedRepositories[namespace]; ok {","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/goharbor/harbor/blob/7b2fd08cc568955cca339afeefab27372840d936/src/pkg/reg/adapter/jfrog/adapter.go#L111-L147","documentation":"Returned by the JFrog Artifactory adapter's PrepareForPush (src/pkg/reg/adapter/jfrog/adapter.go:129) when resource.Metadata.Repository exists but its Name is \"\". The adapter splits the name on \"/\" and uses path[0] as the Artifactory local repository to create, so an empty name cannot map to any repository.","triggerScenarios":"Calling jfrog PrepareForPush with a resource whose Repository struct is present but Name was never assigned — typically after an override strips the name or a clone misses the field.","commonSituations":"Destination-name templating that evaluates to empty; struct copies that keep the Repository pointer but overwrite Name; test fixtures with &model.Repository{} placeholders.","solutions":["Ensure the repository name is propagated (e.g. from the source resource) before calling PrepareForPush: resource.Metadata.Repository.Name = srcRepoName.","Pre-validate names with the helper below so you know which index failed.","If the name is computed from a rule, unit-test the computation against edge cases (empty filters, missing namespace).","Log the full resource before the call when debugging replication failures."],"exampleFix":"// before\nRepository: &model.Repository{},\n\n// after\nRepository: &model.Repository{Name: \"docker-local/\" + src.Metadata.Repository.Name},","handlingStrategy":"validation","validationCode":"for i, r := range resources {\n\tif r == nil || r.Metadata == nil || r.Metadata.Repository == nil || r.Metadata.Repository.Name == \"\" {\n\t\treturn fmt.Errorf(\"resources[%d]: bad resource\", i)\n\t}\n}","typeGuard":"func hasRepoName(r *model.Resource) bool {\n\treturn r != nil && r.Metadata != nil &&\n\t\tr.Metadata.Repository != nil && r.Metadata.Repository.Name != \"\"\n}","tryCatchPattern":"if err := a.PrepareForPush(resources); err != nil {\n\tif strings.Contains(err.Error(), \"name of namespace cannot be null\") {\n\t\t// empty Repository.Name: propagate source repo name and retry\n\t}\n\treturn err\n}","preventionTips":["Derive Repository.Name from the source resource, never from user templates alone.","Test name computation for empty outputs.","Log Metadata.Repository.Name at the boundary."],"tags":["go","jfrog","artifactory","replication","validation","empty-string"],"backgroundTag":null,"analyzedSha":"7b2fd08cc568955cca339afeefab27372840d936","analyzedAt":"2026-08-16T00:00:10.961Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}