<commit_before>package exec

import (
	"context"
	"errors"
	"fmt"
	"io"
	"reflect"
	"regexp"

	"code.cloudfoundry.org/lager"
	"code.cloudfoundry.org/lager/lagerctx"
	"github.com/concourse/concourse/atc/worker/transport"
)

type Retriable struct {
	Cause error
}

func (r Retriable) Error() string {
	return fmt.Sprintf("retriable: %s", r.Cause.Error())
}

type RetryErrorStepDelegate interface {
	Errored(lager.Logger, string)
}

type RetryErrorStep struct {
	Step

	delegate RetryErrorStepDelegate
}

func RetryError(step Step, delegate RetryErrorStepDelegate) Step {
	return RetryErrorStep{
		Step:     step,
		delegate: delegate,
	}
}

func (step RetryErrorStep) Run(ctx context.Context, state RunState) error {
	logger := lagerctx.FromContext(ctx)
	runErr := step.Step.Run(ctx, state)
	if runErr != nil && step.toRetry(logger, runErr) {
		logger.Info("retriable", lager.Data{"error": runErr.Error()})
		step.delegate.Errored(logger, fmt.Sprintf("%s, will retry ...", runErr.Error()))
		runErr = Retriable{runErr}
	}
	return runErr
}

func (step RetryErrorStep) toRetry(logger lager.Logger, err error) bool {
	var transportErr *transport.WorkerMissingError
	var unreachable *transport.WorkerUnreachableError
	re := regexp.MustCompile(`worker .+ disappeared`)
	if ok := errors.As(err, transportErr) || errors.As(err, unreachable); ok {
		logger.Debug("retry-error",
			lager.Data{"err_type": reflect.TypeOf(err).String(), "err": err.Error()})
		return true
	} else if re.MatchString(err.Error()) {
		logger.Debug("retry-error",
			lager.Data{"err_type": reflect.TypeOf(err).String(), "err": err})
		return true
	} else if errors.Is(err, io.EOF) {
		logger.Debug("retry-error",
			lager.Data{"err_type": reflect.TypeOf(err).String(), "err": err.Error()})
		return true

	}
	return false
}<commit_msg>Fix failed test<commit_after>package exec

import (
	"context"
	"errors"
	"fmt"
	"io"
	"reflect"
	"regexp"

	"code.cloudfoundry.org/lager"
	"code.cloudfoundry.org/lager/lagerctx"
	"github.com/concourse/concourse/atc/worker/transport"
)

type Retriable struct {
	Cause error
}

func (r Retriable) Error() string {
	return fmt.Sprintf("retriable: %s", r.Cause.Error())
}

type RetryErrorStepDelegate interface {
	Errored(lager.Logger, string)
}

type RetryErrorStep struct {
	Step

	delegate RetryErrorStepDelegate
}

func RetryError(step Step, delegate RetryErrorStepDelegate) Step {
	return RetryErrorStep{
		Step:     step,
		delegate: delegate,
	}
}

func (step RetryErrorStep) Run(ctx context.Context, state RunState) error {
	logger := lagerctx.FromContext(ctx)
	runErr := step.Step.Run(ctx, state)
	if runErr != nil && step.toRetry(logger, runErr) {
		logger.Info("retriable", lager.Data{"error": runErr.Error()})
		step.delegate.Errored(logger, fmt.Sprintf("%s, will retry ...", runErr.Error()))
		runErr = Retriable{runErr}
	}
	return runErr
}

func (step RetryErrorStep) toRetry(logger lager.Logger, err error) bool {
	var transportErr *transport.WorkerMissingError
	var unreachable *transport.WorkerUnreachableError
	re := regexp.MustCompile(`worker .+ disappeared`)
	if ok := errors.As(err, &transportErr) || errors.As(err, &unreachable); ok {
		logger.Debug("retry-error",
			lager.Data{"err_type": reflect.TypeOf(err).String(), "err": err.Error()})
		return true
	} else if re.MatchString(err.Error()) {
		logger.Debug("retry-error",
			lager.Data{"err_type": reflect.TypeOf(err).String(), "err": err})
		return true
	} else if errors.Is(err, io.EOF) {
		logger.Debug("retry-error",
			lager.Data{"err_type": reflect.TypeOf(err).String(), "err": err.Error()})
		return true

	}
	return false
}
{'fraction_non_alphanumeric': 0.14919578480310594, 'fraction_numerical': 0.0, 'mean_word_length': 4.942339373970346, 'pattern_counts': {'":': 14, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1180135', 'n_tokens_mistral': 1323, 'n_tokens_neox': 1281, 'n_words': 268}