goharbor/harbor · error

[tencent-tcr.PrepareForPush] the namespace of resource canno

Error message

[tencent-tcr.PrepareForPush] the namespace of resource cannot be null

What it means

Returned by the Tencent TCR adapter's PrepareForPush (src/pkg/reg/adapter/tencentcr/adapter.go:221) when resource.Metadata exists but resource.Metadata.Repository is nil. The adapter splits Repository.Name into namespace and repository to call createPrivateNamespace/createRepository, so a nil Repository pointer is rejected before any Tencent API call.

Source

Thrown at src/pkg/reg/adapter/tencentcr/adapter.go:221

		SupportedTriggers: []string{
			model.TriggerTypeManual,
			model.TriggerTypeScheduled,
		},
	}
	return
}

func (a *adapter) PrepareForPush(resources []*model.Resource) (err error) {
	log.Debugf("[tencent-tcr.PrepareForPush]")
	for _, resource := range resources {
		if resource == nil {
			return errors.New("the resource cannot be null")
		}
		if resource.Metadata == nil {
			return errors.New("[tencent-tcr.PrepareForPush] the metadata of resource cannot be null")
		}
		if resource.Metadata.Repository == nil {
			return errors.New("[tencent-tcr.PrepareForPush] the namespace of resource cannot be null")
		}
		if len(resource.Metadata.Repository.Name) == 0 {
			return errors.New("[tencent-tcr.PrepareForPush] the name of the namespace cannot be null")
		}
		var paths = strings.Split(resource.Metadata.Repository.Name, "/")
		var namespace = paths[0]
		var repository = path.Join(paths[1:]...)

		log.Debugf("[tencent-tcr.PrepareForPush.createPrivateNamespace] namespace=%s", namespace)
		err = a.createPrivateNamespace(namespace)
		if err != nil {
			return
		}
		log.Debugf("[tencent-tcr.PrepareForPush.createRepository] namespace=%s, repository=%s", namespace, repository)
		err = a.createRepository(namespace, repository)
		if err != nil {
			return
		}

View on GitHub (pinned to 7b2fd08cc5)

Solutions

  1. Set Metadata.Repository with a non-empty Name for every pushed resource.
  2. Run the slice-wide validation helper first to get the failing index.
  3. Copy the whole Metadata (including Repository pointer) when cloning source resources.
  4. Add a builder unit test asserting Repository != nil.

Example fix

// before
Metadata: &model.ResourceMetadata{Vtags: []string{"v1"}},

// after
Metadata: &model.ResourceMetadata{
    Repository: &model.Repository{Name: "myns/myrepo"},
    Vtags:     []string{"v1"},
},
Defensive patterns

Strategy: validation

Validate before calling

for i, r := range resources {
	if r == nil || r.Metadata == nil || r.Metadata.Repository == nil {
		return fmt.Errorf("resources[%d]: missing resource/metadata/repository", i)
	}
}

Type guard

func hasRepository(r *model.Resource) bool {
	return r != nil && r.Metadata != nil && r.Metadata.Repository != nil
}

Try / catch

if err := a.PrepareForPush(resources); err != nil {
	if strings.Contains(err.Error(), "namespace of resource cannot be null") {
		// set Metadata.Repository before retry
	}
	return err
}

Prevention

When it happens

Trigger: Calling tencentcr PrepareForPush with ResourceMetadata that omits the Repository field (only Vtags/Artifact set).

Common situations: Tag-oriented metadata reused for push; struct clones dropping fields; builders where Repository assignment sits in a rarely-taken branch.

Related errors


AI-assisted analysis of goharbor/harbor@7b2fd08cc5 (2026-08-16). Data as JSON: /api/errors/048f493c52b2b406. Report an issue: GitHub.