...

Source file src/edge-infra.dev/pkg/f8n/warehouse/oci/errors.go

Documentation: edge-infra.dev/pkg/f8n/warehouse/oci

     1  package oci
     2  
     3  import (
     4  	"errors"
     5  	"fmt"
     6  
     7  	v1 "github.com/google/go-containerregistry/pkg/v1"
     8  )
     9  
    10  var (
    11  	// ErrInvalidArtifact occurs when an OCI artifact is not a valid Warehouse artifact
    12  	// TODO?: make custom error type that can provide context about what was missing / invalid
    13  	ErrInvalidArtifact = errors.New("OCI artifact is not a valid Warehouse artifact")
    14  )
    15  
    16  // A ConflictError occurs when conflicting digests for a single package are
    17  // discovered during graph operations.
    18  type ConflictError struct {
    19  	// Name is the name of the package
    20  	Name string
    21  
    22  	// The first digest that was discovered and the newly found digest that
    23  	// conflicts with it.
    24  	Digest            v1.Hash
    25  	ConflictingDigest v1.Hash
    26  }
    27  
    28  // Assert we implement Error
    29  var _ error = (*ConflictError)(nil)
    30  
    31  func (e *ConflictError) Error() string {
    32  	return fmt.Sprintf("conflicting digests for %s: have %s and discovered %s",
    33  		e.Name, e.Digest, e.ConflictingDigest)
    34  }
    35  
    36  // NewConflictErr instantiates a ConflictError
    37  func NewConflictErr(name string, current, conflicting v1.Hash) *ConflictError {
    38  	return &ConflictError{
    39  		Name:              name,
    40  		Digest:            current,
    41  		ConflictingDigest: conflicting,
    42  	}
    43  }
    44  

View as plain text