OSDN Git Service

versoin1.1.9 (#594)
[bytom/vapor.git] / vendor / github.com / tendermint / tmlibs / common / errors.go
1 package common
2
3 import (
4         "fmt"
5 )
6
7 type StackError struct {
8         Err   interface{}
9         Stack []byte
10 }
11
12 func (se StackError) String() string {
13         return fmt.Sprintf("Error: %v\nStack: %s", se.Err, se.Stack)
14 }
15
16 func (se StackError) Error() string {
17         return se.String()
18 }
19
20 //--------------------------------------------------------------------------------------------------
21 // panic wrappers
22
23 // A panic resulting from a sanity check means there is a programmer error
24 // and some guarantee is not satisfied.
25 func PanicSanity(v interface{}) {
26         panic(Fmt("Panicked on a Sanity Check: %v", v))
27 }
28
29 // A panic here means something has gone horribly wrong, in the form of data corruption or
30 // failure of the operating system. In a correct/healthy system, these should never fire.
31 // If they do, it's indicative of a much more serious problem.
32 func PanicCrisis(v interface{}) {
33         panic(Fmt("Panicked on a Crisis: %v", v))
34 }
35
36 // Indicates a failure of consensus. Someone was malicious or something has
37 // gone horribly wrong. These should really boot us into an "emergency-recover" mode
38 func PanicConsensus(v interface{}) {
39         panic(Fmt("Panicked on a Consensus Failure: %v", v))
40 }
41
42 // For those times when we're not sure if we should panic
43 func PanicQ(v interface{}) {
44         panic(Fmt("Panicked questionably: %v", v))
45 }