goharbor/harbor · error
the resource cannot be null
Error message
the resource cannot be null
What it means
Returned by the Tencent TCR adapter's PrepareForPush (src/pkg/reg/adapter/tencentcr/adapter.go:215) when the resources slice contains a nil *model.Resource element. The method pre-creates the TCR namespace and repository before pushing, and dereferences each resource in the loop, so a nil entry is rejected first.
Source
Thrown at src/pkg/reg/adapter/tencentcr/adapter.go:215
},
{
Type: model.FilterTypeTag,
Style: model.FilterStyleTypeText,
},
},
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 {
returnView on GitHub (pinned to 7b2fd08cc5)
Solutions
- Stop appending nil at the construction site; fail fast on fetch errors instead.
- Pre-validate the slice (see validationCode) to report the failing index.
- Keep one builder for resources shared by tests and production.
- Assert non-nil invariants in the pipeline's unit tests.
Example fix
// before
resources = append(resources, r) // r may be nil
// after
if r == nil {
return fmt.Errorf("fetch returned nil resource")
}
resources = append(resources, r) Defensive patterns
Strategy: validation
Validate before calling
for i, r := range resources {
if r == nil {
return fmt.Errorf("resources[%d] is nil", i)
}
} Type guard
func isUsableResource(r *model.Resource) bool { return r != nil } Try / catch
if err := a.PrepareForPush(resources); err != nil {
if strings.Contains(err.Error(), "the resource cannot be null") {
// nil element: fix slice construction
}
return err
} Prevention
- Abort on nil fetch results instead of appending placeholders.
- Validate slices at pipeline boundaries.
- Builder-based tests avoid nil fixtures.
When it happens
Trigger: Calling tencentcr PrepareForPush with a slice built by appending nil (e.g. conditional fetch results) instead of fully-formed resources.
Common situations: Custom transfer code appending placeholders on failure; sparse slices after filtering; refactors that introduce nil defaults; test tables with nil rows reaching shared code.
Related errors
- [tencent-tcr.PrepareForPush] the metadata of resource cannot
- [tencent-tcr.PrepareForPush] the namespace of resource canno
- the name of the repository cannot be null
- the resource cannot be null
- the metadata of resource cannot be null
AI-assisted analysis of goharbor/harbor@7b2fd08cc5 (2026-08-16).
Data as JSON: /api/errors/8174c414dcefa285.
Report an issue: GitHub.