go.uber.org/cadence@v1.2.9/error.go (about)

     1  // Copyright (c) 2017 Uber Technologies, Inc.
     2  //
     3  // Permission is hereby granted, free of charge, to any person obtaining a copy
     4  // of this software and associated documentation files (the "Software"), to deal
     5  // in the Software without restriction, including without limitation the rights
     6  // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     7  // copies of the Software, and to permit persons to whom the Software is
     8  // furnished to do so, subject to the following conditions:
     9  //
    10  // The above copyright notice and this permission notice shall be included in
    11  // all copies or substantial portions of the Software.
    12  //
    13  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    14  // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    15  // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    16  // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    17  // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    18  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    19  // THE SOFTWARE.
    20  
    21  package cadence
    22  
    23  import (
    24  	"go.uber.org/cadence/.gen/go/shared"
    25  	"go.uber.org/cadence/internal"
    26  	"go.uber.org/cadence/workflow"
    27  )
    28  
    29  type (
    30  	// CustomError returned from workflow and activity implementations with reason and optional details.
    31  	CustomError = internal.CustomError
    32  
    33  	// CanceledError returned when operation was canceled.
    34  	CanceledError = internal.CanceledError
    35  
    36  	// NonDeterministicError is returned when a workflow's replay was non-deterministic, and it could not be resumed safely.
    37  	NonDeterministicError = internal.NonDeterministicError
    38  )
    39  
    40  // ErrNoData is returned when trying to extract strong typed data while there is no data available.
    41  var ErrNoData = internal.ErrNoData
    42  
    43  // NewCustomError create new instance of *CustomError with reason and optional details.
    44  // Use CustomError for any use case specific errors that cross activity and child workflow boundaries.
    45  func NewCustomError(reason string, details ...interface{}) *CustomError {
    46  	return internal.NewCustomError(reason, details...)
    47  }
    48  
    49  // NewCanceledError creates CanceledError instance.
    50  // Return this error from activity or child workflow to indicate that it was successfully cancelled.
    51  func NewCanceledError(details ...interface{}) *CanceledError {
    52  	return internal.NewCanceledError(details...)
    53  }
    54  
    55  // IsCustomError return if the err is a CustomError
    56  func IsCustomError(err error) bool {
    57  	_, ok := err.(*CustomError)
    58  	return ok
    59  }
    60  
    61  // IsWorkflowExecutionAlreadyStartedError return if the err is a WorkflowExecutionAlreadyStartedError
    62  func IsWorkflowExecutionAlreadyStartedError(err error) bool {
    63  	_, ok := err.(*shared.WorkflowExecutionAlreadyStartedError)
    64  	return ok
    65  }
    66  
    67  // IsCanceledError return if the err is a CanceledError
    68  func IsCanceledError(err error) bool {
    69  	_, ok := err.(*CanceledError)
    70  	return ok
    71  }
    72  
    73  // IsGenericError return if the err is a GenericError
    74  func IsGenericError(err error) bool {
    75  	_, ok := err.(*workflow.GenericError)
    76  	return ok
    77  }
    78  
    79  // IsTimeoutError return if the err is a TimeoutError
    80  func IsTimeoutError(err error) bool {
    81  	_, ok := err.(*workflow.TimeoutError)
    82  	return ok
    83  }
    84  
    85  // IsTerminatedError return if the err is a TerminatedError
    86  func IsTerminatedError(err error) bool {
    87  	_, ok := err.(*workflow.TerminatedError)
    88  	return ok
    89  }
    90  
    91  // IsPanicError return if the err is a PanicError
    92  func IsPanicError(err error) bool {
    93  	_, ok := err.(*workflow.PanicError)
    94  	return ok
    95  }