2023-11-03 10:44:03 +00:00
|
|
|
package errors
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"go.uber.org/multierr"
|
|
|
|
)
|
|
|
|
|
|
|
|
type PipelineErrorType string
|
|
|
|
|
|
|
|
const (
|
|
|
|
PipelineErrorTypeLinter PipelineErrorType = "linter" // some error with the config syntax
|
|
|
|
PipelineErrorTypeDeprecation PipelineErrorType = "deprecation" // using some deprecated feature
|
|
|
|
PipelineErrorTypeCompiler PipelineErrorType = "compiler" // some error with the config semantics
|
|
|
|
PipelineErrorTypeGeneric PipelineErrorType = "generic" // some generic error
|
2024-02-10 16:33:05 +00:00
|
|
|
PipelineErrorTypeBadHabit PipelineErrorType = "bad_habit" // some bad-habit error
|
2023-11-03 10:44:03 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type PipelineError struct {
|
|
|
|
Type PipelineErrorType `json:"type"`
|
|
|
|
Message string `json:"message"`
|
|
|
|
IsWarning bool `json:"is_warning"`
|
2023-11-12 17:23:48 +00:00
|
|
|
Data any `json:"data"`
|
2023-11-03 10:44:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type LinterErrorData struct {
|
2023-11-04 14:30:47 +00:00
|
|
|
File string `json:"file"`
|
2023-11-03 10:44:03 +00:00
|
|
|
Field string `json:"field"`
|
|
|
|
}
|
|
|
|
|
2023-11-04 14:30:47 +00:00
|
|
|
type DeprecationErrorData struct {
|
|
|
|
File string `json:"file"`
|
|
|
|
Field string `json:"field"`
|
|
|
|
Docs string `json:"docs"`
|
|
|
|
}
|
|
|
|
|
2023-11-03 10:44:03 +00:00
|
|
|
func (e *PipelineError) Error() string {
|
|
|
|
return fmt.Sprintf("[%s] %s", e.Type, e.Message)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *PipelineError) GetLinterData() *LinterErrorData {
|
|
|
|
if e.Type != PipelineErrorTypeLinter {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if data, ok := e.Data.(*LinterErrorData); ok {
|
|
|
|
return data
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetPipelineErrors(err error) []*PipelineError {
|
|
|
|
var pipelineErrors []*PipelineError
|
|
|
|
for _, _err := range multierr.Errors(err) {
|
|
|
|
var err *PipelineError
|
|
|
|
if errors.As(_err, &err) {
|
|
|
|
pipelineErrors = append(pipelineErrors, err)
|
|
|
|
} else {
|
|
|
|
pipelineErrors = append(pipelineErrors, &PipelineError{
|
|
|
|
Message: _err.Error(),
|
|
|
|
Type: PipelineErrorTypeGeneric,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return pipelineErrors
|
|
|
|
}
|
|
|
|
|
|
|
|
func HasBlockingErrors(err error) bool {
|
|
|
|
if err == nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
errs := GetPipelineErrors(err)
|
|
|
|
|
|
|
|
for _, err := range errs {
|
|
|
|
if !err.IsWarning {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|