{"record":{"id":"3a220546574ef1ed","repo":"goharbor/harbor","slug":"the-namespace-of-resource-cannot-be-null-3a2205","errorCode":null,"errorMessage":"the namespace of resource cannot be null","messagePattern":"the namespace of resource cannot be null","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/pkg/reg/adapter/jfrog/adapter.go","lineNumber":126,"sourceCode":"\treturn &adapter{\n\t\tAdapter:  native.NewAdapter(registry),\n\t\tregistry: registry,\n\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}","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/goharbor/harbor/blob/7b2fd08cc568955cca339afeefab27372840d936/src/pkg/reg/adapter/jfrog/adapter.go#L108-L144","documentation":"Returned by the JFrog Artifactory adapter's PrepareForPush (src/pkg/reg/adapter/jfrog/adapter.go:126) when resource.Metadata is non-nil but resource.Metadata.Repository is nil. The adapter needs the Repository pointer to read Name and split out the Artifactory repository key, so a missing Repository aborts push preparation for the entire batch.","triggerScenarios":"Building a model.ResourceMetadata with only Vtags or Artifact fields set (Repository omitted), then calling PrepareForPush on the jfrog adapter.","commonSituations":"Resources assembled for tag-listing or deletion where Repository is not needed and therefore omitted, later fed into the push path; struct-literal refactors that drop fields; copy loops that clone only some fields of the source metadata.","solutions":["Set Metadata.Repository = &model.Repository{Name: ...} whenever the resource will be pushed.","Pre-validate the slice (see validationCode) to get the failing index instead of the adapter's opaque message.","Fix the construction site: ensure metadata cloning copies Repository by reference or value consistently.","Write a unit test over your resource builder asserting Repository is non-nil for push resources."],"exampleFix":"// before\nMetadata: &model.ResourceMetadata{\n    Vtags: []string{\"v1\"},\n},\n\n// after\nMetadata: &model.ResourceMetadata{\n    Repository: &model.Repository{Name: \"docker-local/ubuntu\"},\n    Vtags:     []string{\"v1\"},\n},","handlingStrategy":"validation","validationCode":"for i, r := range resources {\n\tif r == nil || r.Metadata == nil || r.Metadata.Repository == nil {\n\t\treturn fmt.Errorf(\"resources[%d]: nil resource/metadata/repository\", i)\n\t}\n}","typeGuard":"func hasRepository(r *model.Resource) bool {\n\treturn r != nil && r.Metadata != nil && r.Metadata.Repository != nil\n}","tryCatchPattern":"if err := a.PrepareForPush(resources); err != nil {\n\tif strings.Contains(err.Error(), \"namespace of resource cannot be null\") {\n\t\t// Repository pointer missing: populate Metadata.Repository before retry\n\t}\n\treturn err\n}","preventionTips":["Clone source Metadata wholesale instead of field-by-field.","Set Repository in the same literal that sets Metadata.","Test builders assert Repository non-nil."],"tags":["go","jfrog","artifactory","replication","validation","nil-check"],"backgroundTag":null,"analyzedSha":"7b2fd08cc568955cca339afeefab27372840d936","analyzedAt":"2026-08-16T00:00:10.961Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}