emissary/internal/spec/error.go

37 lines
644 B
Go
Raw Normal View History

2023-02-02 10:55:24 +01:00
package spec
import (
"strings"
2023-02-02 10:55:24 +01:00
"github.com/pkg/errors"
"github.com/qri-io/jsonschema"
)
var ErrUnknownSchema = errors.New("unknown schema")
type ValidationError struct {
keyErrors []jsonschema.KeyError
}
func (e *ValidationError) Error() string {
var sb strings.Builder
if _, err := sb.WriteString("validation error: "); err != nil {
panic(errors.WithStack(err))
}
for i, err := range e.keyErrors {
if i != 0 {
if _, err := sb.WriteString(", "); err != nil {
panic(errors.WithStack(err))
}
}
if _, err := sb.WriteString(err.Error()); err != nil {
panic(errors.WithStack(err))
}
}
return sb.String()
}