github.com/blend/go-sdk@v1.20220411.3/ex/option.go (about)

     1  /*
     2  
     3  Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file.
     5  
     6  */
     7  
     8  package ex
     9  
    10  import "fmt"
    11  
    12  // Option is an exception option.
    13  type Option func(*Ex)
    14  
    15  // OptMessage sets the exception message from a given list of arguments with fmt.Sprint(args...).
    16  func OptMessage(args ...interface{}) Option {
    17  	return func(ex *Ex) {
    18  		ex.Message = fmt.Sprint(args...)
    19  	}
    20  }
    21  
    22  // OptMessagef sets the exception message from a given list of arguments with fmt.Sprintf(format, args...).
    23  func OptMessagef(format string, args ...interface{}) Option {
    24  	return func(ex *Ex) {
    25  		ex.Message = fmt.Sprintf(format, args...)
    26  	}
    27  }
    28  
    29  // OptStackTrace sets the exception stack.
    30  func OptStackTrace(stack StackTrace) Option {
    31  	return func(ex *Ex) {
    32  		ex.StackTrace = stack
    33  	}
    34  }
    35  
    36  // OptInner sets an inner or wrapped ex.
    37  func OptInner(inner error) Option {
    38  	return func(ex *Ex) {
    39  		ex.Inner = NewWithStackDepth(inner, DefaultNewStartDepth+2)
    40  	}
    41  }
    42  
    43  // OptInnerClass sets an inner unwrapped exception.
    44  // Use this if you don't want to include a strack trace for a cause.
    45  func OptInnerClass(inner error) Option {
    46  	return func(ex *Ex) {
    47  		ex.Inner = inner
    48  	}
    49  }