<commit_before>package org.embulk.output.sftp.utils;

import org.embulk.spi.Exec;
import org.embulk.spi.util.RetryExecutor;
import org.slf4j.Logger;

public abstract class DefaultRetry<T> implements RetryExecutor.Retryable<T>
{
    private Logger logger = Exec.getLogger(getClass());

    private final String task;

    protected DefaultRetry(String task)
    {
        this.task = task;
    }

    @Override
    public boolean isRetryableException(Exception exception)
    {
        return true;
    }

    @Override
    public void onRetry(Exception exception, int retryCount, int retryLimit, int retryWait)
    {
        String message = String.format("%s failed. Retrying %d/%d after %d seconds. Message: %s",
                task, retryCount, retryLimit, retryWait / 1000, exception.getMessage());
        if (retryCount % 3 == 0) {
            logger.warn(message, exception);
        }
        else {
            logger.warn(message);
        }
    }

    @Override
    public void onGiveup(Exception firstException, Exception lastException)
    {
    }
}<commit_msg>Not retry for Auth error<commit_after>package org.embulk.output.sftp.utils;

import com.jcraft.jsch.JSchException;
import org.embulk.spi.Exec;
import org.embulk.spi.util.RetryExecutor;
import org.slf4j.Logger;

public abstract class DefaultRetry<T> implements RetryExecutor.Retryable<T>
{
    private Logger logger = Exec.getLogger(getClass());

    private final String task;

    protected DefaultRetry(String task)
    {
        this.task = task;
    }

    @Override
    public boolean isRetryableException(Exception exception)
    {
        return !hasRootCauseAuthFail(exception);
    }

    @Override
    public void onRetry(Exception exception, int retryCount, int retryLimit, int retryWait)
    {
        String message = String.format("%s failed. Retrying %d/%d after %d seconds. Message: %s",
                task, retryCount, retryLimit, retryWait / 1000, exception.getMessage());
        if (retryCount % 3 == 0) {
            logger.warn(message, exception);
        }
        else {
            logger.warn(message);
        }
    }

    @Override
    public void onGiveup(Exception firstException, Exception lastException)
    {
    }

    private static boolean isAuthFail(Throwable e)
    {
        return e instanceof JSchException && "USERAUTH fail".equals(e.getMessage());
    }

    private static boolean hasRootCauseAuthFail(Throwable e)
    {
        while (e != null && !isAuthFail(e)) {
            e = e.getCause();
        }
        return e != null;
    }
}
{'fraction_non_alphanumeric': 0.09953161592505855, 'fraction_numerical': 0.00546448087431694, 'mean_word_length': 2.6562054208273893, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '6539389', 'n_tokens_mistral': 755, 'n_tokens_neox': 740, 'n_words': 185}