{"record":{"id":"63716250c4c2918c","repo":"goharbor/harbor","slug":"tencent-tcr-newadapter-invalid-tcr-instance-endp","errorCode":null,"errorMessage":"[tencent-tcr.newAdapter] Invalid TCR instance endpoint","messagePattern":"\\[tencent-tcr\\.newAdapter\\] Invalid TCR instance endpoint","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/pkg/reg/adapter/tencentcr/adapter.go","lineNumber":113,"sourceCode":"**/\nvar _ adp.Adapter = &adapter{}\n\nfunc newAdapter(registry *model.Registry) (a *adapter, err error) {\n\tif !isSecretID(registry.Credential.AccessKey) {\n\t\terr = errors.New(\"[tencent-tcr.newAdapter] Please use SecretId/SecretKey, NOT docker login Username/Password\")\n\t\tlog.Debugf(\"[tencent-tcr.newAdapter] error=%v\", err)\n\t\treturn\n\t}\n\n\t// Query TCR instance info via endpoint.\n\tvar registryURL *url.URL\n\tregistryURL, _ = url.Parse(registry.URL)\n\n\t// only validate registryURL.Host in non-UT scenario\n\tif os.Getenv(\"UTTEST\") != \"true\" {\n\t\tif !strings.Contains(registryURL.Host, \".tencentcloudcr.com\") {\n\t\t\tlog.Errorf(\"[tencent-tcr.newAdapter] errInvalidTcrEndpoint=%v\", err)\n\t\t\treturn nil, errInvalidTcrEndpoint\n\t\t}\n\t}\n\n\trealm, service, err := util.Ping(registry)\n\tlog.Debugf(\"[tencent-tcr.newAdapter] realm=%s, service=%s error=%v\", realm, service, err)\n\tif err != nil {\n\t\tlog.Errorf(\"[tencent-tcr.newAdapter] ping failed. error=%v\", err)\n\t\treturn\n\t}\n\n\t// Create TCR API client\n\tvar tcrCredential = common.NewCredential(registry.Credential.AccessKey, registry.Credential.AccessSecret)\n\tvar cfp = profile.NewClientProfile()\n\tvar client *tcr.Client\n\t// temp client used to get TCR instance info\n\tclient, err = tcr.NewClient(tcrCredential, regions.Guangzhou, cfp)\n\tif err != nil {\n\t\treturn","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/goharbor/harbor/blob/7b2fd08cc568955cca339afeefab27372840d936/src/pkg/reg/adapter/tencentcr/adapter.go#L95-L131","documentation":"Returned by newAdapter for the Tencent TCR adapter (src/pkg/reg/adapter/tencentcr/adapter.go:113) when the parsed registry URL's host does not contain '.tencentcloudcr.com'. The adapter only operates against TCR instance endpoints because it drives Tencent Cloud APIs keyed off that host; the check is skipped when UTTEST=true for unit tests. Note url.Parse's error is deliberately ignored, so a malformed URL falls through to this host check.","triggerScenarios":"Creating a tencentcr adapter with registry.URL whose host lacks '.tencentcloudcr.com' — e.g. 'https://hub.docker.com', a custom CDN domain, a URL with a typo, or a URL so malformed that Host parses empty. Only the host substring is examined; scheme and path are irrelevant.","commonSituations":"Wrong registry type selected in an endpoint config (docker-hub adapter pointed at tencentcr or vice versa); using a private-domain/fronted TCR endpoint; copy-paste errors in the registry URL; trailing text after the host.","solutions":["Set registry.URL to the TCR instance endpoint shown in the TCR console, e.g. 'https://<name>-<account>.tencentcloudcr.com'.","Verify which adapter factory matches your URL: if the endpoint is not TCR, configure the registry type (docker-registry/harbor/...) accordingly so the tencentcr adapter is not selected.","Check the URL parses cleanly (url.Parse + inspect Host) before constructing the adapter.","If you must use a custom domain in unit tests, set UTTEST=true — never in production."],"exampleFix":"// before\nregistry.URL = \"https://my-mirror.example.com\"\nadp, err := tencentcr.NewAdapter(registry) // errInvalidTcrEndpoint\n\n// after\nregistry.URL = \"https://myinstance-1250000000.tencentcloudcr.com\"\nadp, err := tencentcr.NewAdapter(registry)","handlingStrategy":"validation","validationCode":"u, err := url.Parse(registry.URL)\nif err != nil || u.Host == \"\" {\n\treturn fmt.Errorf(\"registry URL %q is not parseable\", registry.URL)\n}\nif !strings.Contains(u.Host, \".tencentcloudcr.com\") {\n\treturn fmt.Errorf(\"%q is not a TCR instance endpoint\", u.Host)\n}\nadapter, err := tencentcr.NewAdapter(registry)","typeGuard":"func isTcrEndpoint(raw string) bool {\n\tu, err := url.Parse(raw)\n\treturn err == nil && strings.Contains(u.Host, \".tencentcloudcr.com\")\n}","tryCatchPattern":"a, err := tencentcr.NewAdapter(registry)\nif err != nil {\n\tif strings.Contains(err.Error(), \"Invalid TCR instance endpoint\") {\n\t\t// configuration error: fix registry.URL or select the right adapter type\n\t}\n\treturn nil, err\n}","preventionTips":["Copy the endpoint exactly from the TCR console ('https://<name>-<account>.tencentcloudcr.com').","Validate the URL host before registering the endpoint.","Match adapter/registry type to the endpoint; do not force non-TCR URLs through tencentcr.","Never set UTTEST=true in production to bypass the check."],"tags":["go","tencent-tcr","tencentcloud","registry-endpoint","configuration"],"backgroundTag":null,"analyzedSha":"7b2fd08cc568955cca339afeefab27372840d936","analyzedAt":"2026-08-16T00:00:10.961Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}