Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /*
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
  *     http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.facebook.presto.util;
import static com.facebook.presto.util.ImmutableCollectors.toImmutableList;
import static com.google.common.base.Functions.toStringFunction;
import static java.lang.String.format;
import static java.util.Arrays.asList;
public final class Failures
    public static final String WORKER_NODE_ERROR = "" +
            "Encountered too many errors talking to a worker node. " +
            "The node may have crashed or be under too much load. " +
            "This is probably a transient issue, so please retry your query in a few minutes.";
    private Failures() {}
    public static ExecutionFailureInfo toFailure(Throwable failure)
    {
        if (failure == null) {
            return null;
        }
        // todo prevent looping with suppressed cause loops and such
        String type;
        if (failure instanceof Failure) {
            type = ((Failurefailure).getType();
        }
        else {
            type = failure.getClass().getCanonicalName();
        }
        ErrorCode errorCode = null;
        if (failure instanceof PrestoException) {
            errorCode = ((PrestoExceptionfailure).getErrorCode();
        }
        else if (failure instanceof Failure) {
            errorCode = ((Failurefailure).getErrorCode();
        }
        return new ExecutionFailureInfo(type,
                failure.getMessage(),
                toFailure(failure.getCause()),
                toFailures(asList(failure.getSuppressed())),
                Lists.transform(asList(failure.getStackTrace()), toStringFunction()),
                getErrorLocation(failure),
                errorCode);
    }
    public static void checkCondition(boolean conditionErrorCodeSupplier errorCodeString formatStringObject... args)
    {
        if (!condition) {
            throw new PrestoException(errorCodeformat(formatStringargs));
        }
    }
    public static List<ExecutionFailureInfotoFailures(Collection<? extends Throwablefailures)
    {
        return failures.stream()
                .map(Failures::toFailure)
                .collect(toImmutableList());
    }
    @Nullable
    private static ErrorLocation getErrorLocation(Throwable throwable)
    {
        // TODO: this is a big hack
        if (throwable instanceof ParsingException) {
            ParsingException e = (ParsingExceptionthrowable;
            return new ErrorLocation(e.getLineNumber(), e.getColumnNumber());
        }
        return null;
    }
New to GrepCode? Check out our FAQ X