chore: bump minimum Go to 1.26 and adopt 1.26 features (#2920)

This commit is contained in:
Valentin Maerten
2026-08-20 12:24:04 +02:00
committed by GitHub
parent 325e3188f0
commit dd4463ec60
21 changed files with 76 additions and 73 deletions

View File

@@ -25,8 +25,7 @@ type (
func NewTaskfileDecodeError(err error, node *yaml.Node) *TaskfileDecodeError {
// If the error is already a DecodeError, return it
taskfileInvalidErr := &TaskfileDecodeError{}
if errors.As(err, &taskfileInvalidErr) {
if taskfileInvalidErr, ok := errors.AsType[*TaskfileDecodeError](err); ok {
return taskfileInvalidErr
}
return &TaskfileDecodeError{
@@ -45,8 +44,7 @@ func (err *TaskfileDecodeError) Error() string {
fmt.Fprintln(buf, color.RedString("err: %s", err.Message))
} else {
// Extract the errors from the TypeError
te := &yaml.TypeError{}
if errors.As(err.Err, &te) {
if te, ok := errors.AsType[*yaml.TypeError](err.Err); ok {
if len(te.Errors) > 1 {
fmt.Fprintln(buf, color.RedString("errs:"))
for _, message := range te.Errors {

View File

@@ -67,6 +67,13 @@ func As(err error, target any) bool {
return errors.As(err, target)
}
// AsType wraps the standard errors.AsType function so that we don't need to alias
// that package. It returns the first error in err's tree that matches type T, and
// whether such an error was found.
func AsType[T error](err error) (T, bool) {
return errors.AsType[T](err)
}
// Unwrap wraps the standard errors.Unwrap function so that we don't need to alias that package.
func Unwrap(err error) error {
return errors.Unwrap(err)

View File

@@ -48,12 +48,10 @@ func (err *TaskRunError) Code() int {
}
func (err *TaskRunError) TaskExitCode() int {
var exit interp.ExitStatus
if errors.As(err.Err, &exit) {
if exit, ok := errors.AsType[interp.ExitStatus](err.Err); ok {
return int(exit)
}
var timeout *TaskTimeoutError
if errors.As(err.Err, &timeout) {
if _, ok := errors.AsType[*TaskTimeoutError](err.Err); ok {
return TimeoutExitCode
}
return err.Code()