{"record":{"id":"13dfce0bf53e203b","repo":"goharbor/harbor","slug":"tencent-tcr-prepareforpush-the-name-of-the-names","errorCode":null,"errorMessage":"[tencent-tcr.PrepareForPush] the name of the namespace cannot be null","messagePattern":"\\[tencent-tcr\\.PrepareForPush\\] the name of the namespace cannot be null","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/pkg/reg/adapter/tencentcr/adapter.go","lineNumber":224,"sourceCode":"\t\t},\n\t}\n\treturn\n}\n\nfunc (a *adapter) PrepareForPush(resources []*model.Resource) (err error) {\n\tlog.Debugf(\"[tencent-tcr.PrepareForPush]\")\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(\"[tencent-tcr.PrepareForPush] the metadata of resource cannot be null\")\n\t\t}\n\t\tif resource.Metadata.Repository == nil {\n\t\t\treturn errors.New(\"[tencent-tcr.PrepareForPush] 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(\"[tencent-tcr.PrepareForPush] the name of the namespace cannot be null\")\n\t\t}\n\t\tvar paths = strings.Split(resource.Metadata.Repository.Name, \"/\")\n\t\tvar namespace = paths[0]\n\t\tvar repository = path.Join(paths[1:]...)\n\n\t\tlog.Debugf(\"[tencent-tcr.PrepareForPush.createPrivateNamespace] namespace=%s\", namespace)\n\t\terr = a.createPrivateNamespace(namespace)\n\t\tif err != nil {\n\t\t\treturn\n\t\t}\n\t\tlog.Debugf(\"[tencent-tcr.PrepareForPush.createRepository] namespace=%s, repository=%s\", namespace, repository)\n\t\terr = a.createRepository(namespace, repository)\n\t\tif err != nil {\n\t\t\treturn\n\t\t}\n\t}\n\n\treturn","sourceCodeStart":206,"sourceCodeEnd":242,"githubUrl":"https://github.com/goharbor/harbor/blob/7b2fd08cc568955cca339afeefab27372840d936/src/pkg/reg/adapter/tencentcr/adapter.go#L206-L242","documentation":"Returned by the Tencent TCR adapter's PrepareForPush (src/pkg/reg/adapter/tencentcr/adapter.go:224) when resource.Metadata.Repository.Name is the empty string. The name is split on \"/\" to derive the namespace (paths[0]) and repository (paths[1:]) that the adapter creates in TCR; an empty name has no namespace segment and is rejected.","triggerScenarios":"Calling tencentcr PrepareForPush with a Repository whose Name is \"\" — typically after a name-override produced empty or a clone dropped the field.","commonSituations":"Destination naming templates evaluating to empty; field dropped during struct copy; placeholder fixtures (&model.Repository{}); upstream fetch failing to set the name silently.","solutions":["Ensure Name is a non-empty 'namespace/repository' string before the call.","Pre-validate names (see validationCode) to report the exact failing index.","Unit-test name computation against empty/edge-case inputs.","Log resource.Metadata.Repository.Name at the pipeline boundary when triaging."],"exampleFix":"// before\nRepository: &model.Repository{},\n\n// after\nRepository: &model.Repository{Name: \"myns/myrepo\"},","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]: invalid 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 the namespace cannot be null\") {\n\t\t// empty Repository.Name: set 'namespace/repo' and retry\n\t}\n\treturn err\n}","preventionTips":["Propagate the source repository name into every derived resource.","Test name computation against empty inputs.","Validate at the boundary with an index-reporting helper."],"tags":["go","tencent-tcr","replication","validation","empty-string"],"backgroundTag":null,"analyzedSha":"7b2fd08cc568955cca339afeefab27372840d936","analyzedAt":"2026-08-16T00:00:10.961Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}