    001/*
    002 * Copyright (c) 2007-2017 Xplenty, Inc. All Rights Reserved.
    003 *
    004 * Project and contact information: http://www.cascading.org/
    005 *
    006 * This file is part of the Cascading project.
    007 *
    008 * Licensed under the Apache License, Version 2.0 (the "License");
    009 * you may not use this file except in compliance with the License.
    010 * You may obtain a copy of the License at
    011 *
    012 *     http://www.apache.org/licenses/LICENSE-2.0
    013 *
    014 * Unless required by applicable law or agreed to in writing, software
    015 * distributed under the License is distributed on an "AS IS" BASIS,
    016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    017 * See the License for the specific language governing permissions and
    018 * limitations under the License.
    019 */
    020
    021package cascading.tap;
    022
    023import cascading.CascadingException;
    024import cascading.tuple.Fields;
    025import cascading.tuple.Tuple;
    026import cascading.util.TraceUtil;
    027
    028/**
    029 * Class TapException is thrown from {@link Tap} and {@link cascading.scheme.Scheme} subclasses.
    030 * <p/>
    031 * Use the payload {@link Tuple} constructor if being thrown from inside a Scheme and which for specific data
    032 * to be trapped by a failure trap Tap. If the payload is not null, and there is a trap covering the source or sink
    033 * Tap in question, it will be written to the trap Tap.
    034 */
    035public class TapException extends CascadingException
    036  {
    037  Tuple payload;
    038
    039  /** Constructor TapException creates a new TapException instance. */
    040  public TapException()
    041    {
    042    }
    043
    044  /**
    045   * Constructor TapException creates a new TapException instance.
    046   *
    047   * @param string of type String
    048   */
    049  public TapException( String string )
    050    {
    051    super( string );
    052    }
    053
    054  /**
    055   * Constructor TapException creates a new TapException instance.
    056   *
    057   * @param string    of type String
    058   * @param throwable of type Throwable
    059   */
    060  public TapException( String string, Throwable throwable )
    061    {
    062    super( string, throwable );
    063    }
    064
    065  /**
    066   * Constructor TapException creates a new TapException instance.
    067   *
    068   * @param string    of type String
    069   * @param throwable of type Throwable
    070   * @param payload   of type Tuple
    071   */
    072  public TapException( String string, Throwable throwable, Tuple payload )
    073    {
    074    super( string, throwable );
    075    this.payload = payload;
    076    }
    077
    078  /**
    079   * Constructor TapException creates a new TapException instance.
    080   *
    081   * @param string  of type String
    082   * @param payload of type Tuple
    083   */
    084  public TapException( String string, Tuple payload )
    085    {
    086    super( string );
    087    this.payload = payload;
    088    }
    089
    090  /**
    091   * Constructor TapException creates a new TapException instance.
    092   *
    093   * @param throwable of type Throwable
    094   */
    095  public TapException( Throwable throwable )
    096    {
    097    super( throwable );
    098    }
    099
    100  /**
    101   * Constructor TapException creates a new TapException instance.
    102   *
    103   * @param tap            of type Tap
    104   * @param incomingFields of type Fields
    105   * @param selectorFields of type Fields
    106   * @param throwable      of type Throwable
    107   */
    108  public TapException( Tap tap, Fields incomingFields, Fields selectorFields, Throwable throwable )
    109    {
    110    super( createMessage( tap, incomingFields, selectorFields ), throwable );
    111    }
    112
    113  public Tuple getPayload()
    114    {
    115    return payload;
    116    }
    117
    118  private static String createMessage( Tap tap, Fields incomingFields, Fields selectorFields )
    119    {
    120    String message = "unable to resolve scheme sink selector: " + selectorFields.printVerbose() +
    121      ", with incoming: " + incomingFields.printVerbose();
    122
    123    return TraceUtil.formatTrace( tap.getScheme(), message );
    124    }
    125  }