-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy patherrors.go
More file actions
91 lines (82 loc) · 2.83 KB
/
Copy patherrors.go
File metadata and controls
91 lines (82 loc) · 2.83 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package skill
import (
"errors"
"fmt"
"sort"
"strings"
)
var (
// ErrSkillKeyConflict identifies conflicting declarations of one skill key.
ErrSkillKeyConflict = errors.New("agentadaptor: skill key defined with conflicting sources")
// ErrSkillMaterializationFailed identifies a failure to stage a skill.
ErrSkillMaterializationFailed = errors.New("agentadaptor: skill materialization failed")
// ErrSkillSourceMissing identifies a skill declaration without a source.
ErrSkillSourceMissing = errors.New("agentadaptor: skill source is required")
// ErrSkillKeyMissing identifies a skill declaration without a key.
ErrSkillKeyMissing = errors.New("agentadaptor: skill key is required")
// ErrSkillNotFound identifies a catalogue key that a Provider cannot resolve.
ErrSkillNotFound = errors.New("agentadaptor: skill not found in provider")
)
// SkillKeyConflictError reports two structurally different declarations with
// the same skill key.
type SkillKeyConflictError struct {
// Key is the conflicting skill key.
Key string
// Sources describes the declarations that conflict.
Sources []string
// Detail contains optional diagnostic context.
Detail string
}
// Error implements error.
func (e *SkillKeyConflictError) Error() string {
if e == nil {
return ErrSkillKeyConflict.Error()
}
parts := append([]string(nil), e.Sources...)
sort.Strings(parts)
msg := fmt.Sprintf("agentadaptor: skill key %q is defined by multiple sources with different content", e.Key)
if len(parts) > 0 {
msg += " [" + strings.Join(parts, ", ") + "]"
}
if strings.TrimSpace(e.Detail) != "" {
msg += ": " + e.Detail
}
return msg
}
// Unwrap exposes [ErrSkillKeyConflict] for errors.Is.
func (e *SkillKeyConflictError) Unwrap() error { return ErrSkillKeyConflict }
// SkillMaterializationError reports a failure to stage a resolved skill into
// a provider-visible directory.
type SkillMaterializationError struct {
// Key is the logical skill key.
Key string
// RuntimeName is the provider-visible directory name, when known.
RuntimeName string
// Cause is the underlying materialization failure.
Cause error
}
// Error implements error.
func (e *SkillMaterializationError) Error() string {
if e == nil {
return ErrSkillMaterializationFailed.Error()
}
msg := fmt.Sprintf("agentadaptor: skill %q materialization failed", e.Key)
if strings.TrimSpace(e.RuntimeName) != "" && e.RuntimeName != e.Key {
msg += fmt.Sprintf(" (runtime name %q)", e.RuntimeName)
}
if e.Cause != nil {
msg += ": " + e.Cause.Error()
}
return msg
}
// Unwrap preserves the underlying materializer cause.
func (e *SkillMaterializationError) Unwrap() error {
if e == nil {
return nil
}
return e.Cause
}
// Is also classifies the error as [ErrSkillMaterializationFailed].
func (e *SkillMaterializationError) Is(target error) bool {
return target == ErrSkillMaterializationFailed
}