Skip to content

Commit 07c3823

Browse files
committed
follow coderabbitai: add sentinel error and improve error handling
On-behalf-of: Gerald Morrison (SAP) <gerald.morrison@sap.com> Signed-off-by: Gerald Morrison (SAP) <gerald.morrison@sap.com>
1 parent cbbd0f4 commit 07c3823

File tree

3 files changed

+44
-6
lines changed

3 files changed

+44
-6
lines changed

bindings/go/constructor/construct.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ import (
3030
// e.g. because the component version already exists in the target repository.
3131
var ErrShouldSkipConstruction = errors.New("should skip construction")
3232

33+
// ErrDigestProcessorNotFound is returned by ResourceDigestProcessorProvider.GetDigestProcessor when no digest
34+
// processor is available for the given access type. This is distinct from operational errors (e.g. plugin start
35+
// failures) and signals that digest processing should be skipped for the resource.
36+
var ErrDigestProcessorNotFound = errors.New("digest processor not found")
37+
3338
const AttributeDescriptor string = "constructor/descriptor"
3439

3540
type Constructor interface {
@@ -425,9 +430,11 @@ func (c *DefaultConstructor) processResource(ctx context.Context, targetRepo Tar
425430
if res, err = digestProcessor.ProcessResourceDigest(ctx, res, creds); err != nil {
426431
return nil, fmt.Errorf("error processing resource %q with digest processor: %w", resource.ToIdentity(), err)
427432
}
428-
} else {
429-
logger.Debug("no digest processor found for resource, skipping digest processing", "error", err)
433+
} else if errors.Is(err, ErrDigestProcessorNotFound) {
434+
logger.Debug("no digest processor found for resource, skipping digest processing")
430435
err = nil
436+
} else {
437+
return nil, fmt.Errorf("error getting digest processor for resource %q: %w", resource.ToIdentity(), err)
431438
}
432439
}
433440
}

bindings/go/constructor/construct_resource_test.go

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ func TestConstructWithResourceDigest(t *testing.T) {
538538

539539
func TestConstructWithResourceAccessSucceedsWhenNoDigestProcessorRegistered(t *testing.T) {
540540
mockDigestProvider := &mockDigestProcessorProvider{
541-
err: fmt.Errorf("no digest processor registered for access type"),
541+
err: fmt.Errorf("no digest processor registered for access type: %w", ErrDigestProcessorNotFound),
542542
}
543543

544544
constructor := setupTestComponent(t, `
@@ -547,7 +547,7 @@ func TestConstructWithResourceAccessSucceedsWhenNoDigestProcessorRegistered(t *t
547547
relation: external
548548
type: helmChart
549549
access:
550-
type: helm/v1
550+
type: Helm/v1
551551
helmRepository: https://charts.example.com
552552
helmChart: my-chart:1.0.0
553553
`)
@@ -579,6 +579,37 @@ func TestConstructWithResourceAccessSucceedsWhenNoDigestProcessorRegistered(t *t
579579
assert.Len(t, mockTargetRepo.addedVersions, 1)
580580
}
581581

582+
func TestConstructWithResourceAccessFailsOnDigestProcessorError(t *testing.T) {
583+
mockDigestProvider := &mockDigestProcessorProvider{
584+
err: fmt.Errorf("plugin process crashed"),
585+
}
586+
587+
constructor := setupTestComponent(t, `
588+
- name: test-resource
589+
version: v1.0.0
590+
relation: external
591+
type: helmChart
592+
access:
593+
type: Helm/v1
594+
helmRepository: https://charts.example.com
595+
helmChart: my-chart:1.0.0
596+
`)
597+
598+
mockTargetRepo := newMockTargetRepository()
599+
600+
opts := Options{
601+
TargetRepositoryProvider: &mockTargetRepositoryProvider{repo: mockTargetRepo},
602+
ResourceDigestProcessorProvider: mockDigestProvider,
603+
}
604+
605+
constructorInstance := NewDefaultConstructor(constructor, opts)
606+
607+
err := constructorInstance.Construct(t.Context())
608+
require.Error(t, err)
609+
assert.Contains(t, err.Error(), "error getting digest processor")
610+
assert.Contains(t, err.Error(), "plugin process crashed")
611+
}
612+
582613
func TestConstructWithInvalidInputMethod(t *testing.T) {
583614
constructor := setupTestComponent(t, `
584615
- name: test-resource

bindings/go/plugin/manager/registries/digestprocessor/registry.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ func (r *RepositoryRegistry) GetPlugin(ctx context.Context, spec runtime.Typed)
137137
if ok := r.scheme.IsRegistered(typ); ok {
138138
p, ok := r.internalDigestProcessorPlugins[typ]
139139
if !ok {
140-
return nil, fmt.Errorf("no internal plugin registered for type %v", typ)
140+
return nil, fmt.Errorf("no internal plugin registered for type %v: %w", typ, constructor.ErrDigestProcessorNotFound)
141141
}
142142

143143
return p, nil
@@ -154,7 +154,7 @@ func (r *RepositoryRegistry) GetPlugin(ctx context.Context, spec runtime.Typed)
154154
func (r *RepositoryRegistry) getPlugin(ctx context.Context, typ runtime.Type) (digestprocessorv1.ResourceDigestProcessorContract, error) {
155155
plugin, ok := r.registry[typ]
156156
if !ok {
157-
return nil, fmt.Errorf("failed to get plugin for typ %q", typ)
157+
return nil, fmt.Errorf("failed to get plugin for typ %q: %w", typ, constructor.ErrDigestProcessorNotFound)
158158
}
159159

160160
if existingPlugin, ok := r.constructedPlugins[plugin.ID]; ok {

0 commit comments

Comments
 (0)