-
Notifications
You must be signed in to change notification settings - Fork 291
/
errors.go
42 lines (34 loc) · 1.07 KB
/
errors.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//
// (C) Copyright 2022 Intel Corporation.
//
// SPDX-License-Identifier: BSD-2-Clause-Patent
//
package build
import (
"fmt"
"strings"
"github.com/pkg/errors"
)
// ErrIncompatComponents is returned when two components are incompatible.
type ErrIncompatComponents struct {
Components []*VersionedComponent
}
func (e ErrIncompatComponents) Error() string {
compStrs := make([]string, len(e.Components))
for i, c := range e.Components {
compStrs[i] = fmt.Sprintf("%s:%s", c.Component, c.Version)
}
return fmt.Sprintf("incompatible components: %s", strings.Join(compStrs, ", "))
}
func errIncompatComponents(components ...*VersionedComponent) error {
return ErrIncompatComponents{components}
}
// IsIncompatComponents returns true if the error is an instance of ErrIncompatComponents.
func IsIncompatComponents(err error) bool {
_, ok := errors.Cause(err).(ErrIncompatComponents)
return ok
}
var (
// ErrNoCtxMetadata is returned when no component/version metadata is found in the context.
ErrNoCtxMetadata = errors.New("no component/version metadata found in context")
)