goharbor/harbor · error

[volcengine-cr.PrepareForPush] the name of the namespace can

Error message

[volcengine-cr.PrepareForPush] the name of the namespace cannot be null

What it means

Returned by the Volcengine CR adapter's PrepareForPush (src/pkg/reg/adapter/volcenginecr/adapter.go:144) when resource.Metadata.Repository.Name is the empty string. The adapter splits the name into namespace/repository; an empty name is rejected before the split. (Distinct from the sibling 'the name of the repository and namespace cannot be null' error at :149, which fires when the name is non-empty but contains no '/', i.e. len(paths) < 2.)

Source

Thrown at src/pkg/reg/adapter/volcenginecr/adapter.go:144

			model.TriggerTypeScheduled,
		},
	}
	return
}

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

		log.Debugf("namespace=%s", namespace)
		err = a.createNamespace(namespace)
		if err != nil {
			log.Errorf("PrepareForPush error :%v", err)
			return
		}
		log.Debugf("namespace=%s, repository=%s", namespace, repository)
		err = a.createRepository(namespace, repository)
		if err != nil {
			log.Errorf("PrepareForPush error :%v", err)

View on GitHub (pinned to 7b2fd08cc5)

Solutions

  1. Ensure Name is non-empty AND contains a '/' (volcenginecr requires 'namespace/repository').
  2. Pre-validate names with the helper below.
  3. Test name-computation code paths against empty inputs.
  4. Log resource.Metadata.Repository.Name at the boundary when triaging replication failures.

Example fix

// before
Repository: &model.Repository{},

// after
Repository: &model.Repository{Name: "myteam/myrepo"},
Defensive patterns

Strategy: validation

Validate before calling

for i, r := range resources {
	if r == nil || r.Metadata == nil || r.Metadata.Repository == nil || r.Metadata.Repository.Name == "" {
		return fmt.Errorf("resources[%d]: invalid resource", i)
	}
	if !strings.Contains(r.Metadata.Repository.Name, "/") {
		return fmt.Errorf("resources[%d]: name must be 'namespace/repository'", i)
	}
}

Type guard

func hasVolcRepoName(r *model.Resource) bool {
	return r != nil && r.Metadata != nil && r.Metadata.Repository != nil &&
		str.Contains(r.Metadata.Repository.Name, "/")
	// note: guard against empty string first; volcenginecr also rejects single-segment names
}

Try / catch

if err := a.PrepareForPush(resources); err != nil {
	if strings.Contains(err.Error(), "name of the namespace cannot be null") {
		// empty Repository.Name: set a non-empty value and retry
	} else if strings.Contains(err.Error(), "repository and namespace cannot be null") {
		// name lacked '/': use 'namespace/repository' form
	}
	return err
}

Prevention

When it happens

Trigger: Calling volcenginecr PrepareForPush with a Repository whose Name is "" — name never set or cleared by an override.

Common situations: Destination naming template evaluating to empty; struct copy dropping Name; placeholder fixtures; upstream fetch silently producing empty names.

Related errors


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