github.com/hasnat/dolt/go@v0.0.0-20210628190320-9eb5d843fbb7/libraries/doltcore/table/pipeline/errors.go (about)

     1  // Copyright 2019 Dolthub, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package pipeline
    16  
    17  import (
    18  	"github.com/dolthub/dolt/go/libraries/doltcore/row"
    19  )
    20  
    21  // TransformRowFailure is an error implementation that stores the row that failed to transform, the transform that
    22  // failed and some details of the error
    23  type TransformRowFailure struct {
    24  	Row           row.Row
    25  	TransformName string
    26  	Details       string
    27  }
    28  
    29  // Error returns a string containing details of the error that occurred
    30  func (trf *TransformRowFailure) Error() string {
    31  	return trf.TransformName + " failed processing"
    32  }
    33  
    34  // IsTransformFailure will return true if the error is an instance of a TransformRowFailure
    35  func IsTransformFailure(err error) bool {
    36  	_, ok := err.(*TransformRowFailure)
    37  	return ok
    38  }
    39  
    40  // GetTransFailureTransName extracts the name of the transform that failed from an error that is an instance of a
    41  // TransformRowFailure
    42  func GetTransFailureTransName(err error) string {
    43  	trf, ok := err.(*TransformRowFailure)
    44  
    45  	if !ok {
    46  		panic("Verify error using IsTransformFailure before calling this.")
    47  	}
    48  
    49  	return trf.TransformName
    50  }
    51  
    52  // GetTransFailureRow extracts the row that failed from an error that is an instance of a TransformRowFailure
    53  func GetTransFailureRow(err error) row.Row {
    54  	trf, ok := err.(*TransformRowFailure)
    55  
    56  	if !ok {
    57  		panic("Verify error using IsTransformFailure before calling this.")
    58  	}
    59  
    60  	return trf.Row
    61  
    62  }
    63  
    64  // GetTransFailureDetails extracts the details string from an error that is an instance of a TransformRowFailure
    65  func GetTransFailureDetails(err error) string {
    66  	trf, ok := err.(*TransformRowFailure)
    67  
    68  	if !ok {
    69  		panic("Verify error using IsTransformFailure before calling this.")
    70  	}
    71  
    72  	return trf.Details
    73  }