github.com/insolar/vanilla@v0.0.0-20201023172447-248fdf805322/throw/throwables.go (about)

     1  // Copyright 2020 Insolar Network Ltd.
     2  // All rights reserved.
     3  // This material is licensed under the Insolar License version 1.0,
     4  // available at https://github.com/insolar/assured-ledger/blob/master/LICENSE.md.
     5  
     6  package throw
     7  
     8  // IllegalValue is to indicate that an argument provided to a calling function is incorrect
     9  // This error captures the topmost entry of caller's stack.
    10  func IllegalValue() error {
    11  	return newMsg("illegal value", 0)
    12  }
    13  
    14  // IllegalState is to indicate that an internal state of a function/object is incorrect or unexpected
    15  // This error captures the topmost entry of caller's stack.
    16  func IllegalState() error {
    17  	return newMsg("illegal state", 0)
    18  }
    19  
    20  // Unsupported is to indicate that a calling function is unsupported intentionally and will remain so for awhile
    21  // This error captures the topmost entry of caller's stack.
    22  func Unsupported() error {
    23  	return newMsg("unsupported", 0)
    24  }
    25  
    26  // NotImplemented is to indicate that a calling function was not yet implemented, but it is expected to be completed soon
    27  // This error captures the topmost entry of caller's stack.
    28  func NotImplemented() error {
    29  	return newMsg("not implemented", 0)
    30  }
    31  
    32  // Impossible is to indicate that the point can never be reached.
    33  // This error captures the topmost entry of caller's stack.
    34  func Impossible() error {
    35  	return newMsg("impossible", 0)
    36  }
    37  
    38  // FailHere creates an error that captures the topmost entry of caller's stack.
    39  func FailHere(msg string) error {
    40  	return newMsg(msg, 0)
    41  }
    42  
    43  // FailCaller creates an error that captures the entry of caller's stack after skipping (skipFrames).
    44  func FailCaller(msg string, skipFrames int) error {
    45  	return newMsg(msg, skipFrames)
    46  }
    47  
    48  func newMsg(msg string, skipFrames int) msgWrap {
    49  	return msgWrap{st: CaptureStackTop(skipFrames + 2), msg: msg}
    50  }