mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-06 08:07:11 +00:00
panic wrapper functions
This commit is contained in:
+1
-1
@@ -209,7 +209,7 @@ func (bA *BitArray) PickRandom() (int, bool) {
|
||||
return 64*elemIdx + bitIdx, true
|
||||
}
|
||||
}
|
||||
panic("should not happen")
|
||||
PanicSanity("should not happen")
|
||||
}
|
||||
} else {
|
||||
// Special case for last elem, to ignore straggler bits
|
||||
|
||||
@@ -16,3 +16,30 @@ func (se StackError) String() string {
|
||||
func (se StackError) Error() string {
|
||||
return se.String()
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
// panic wrappers
|
||||
|
||||
// A panic resulting from a sanity check means there is a programmer error
|
||||
// and some gaurantee is not satisfied.
|
||||
func PanicSanity(v interface{}) {
|
||||
panic(Fmt("Paniced on a Sanity Check: %v", v))
|
||||
}
|
||||
|
||||
// A panic here means something has gone horribly wrong, in the form of data corruption or
|
||||
// failure of the operating system. In a correct/healthy system, these should never fire.
|
||||
// If they do, it's indicative of a much more serious problem.
|
||||
func PanicCrisis(v interface{}) {
|
||||
panic(Fmt("Paniced on a Crisis: %v", v))
|
||||
}
|
||||
|
||||
// Indicates a failure of consensus. Someone was malicious or something has
|
||||
// gone horribly wrong. These should really boot us into an "emergency-recover" mode
|
||||
func PanicConsensus(v interface{}) {
|
||||
panic(Fmt("Paniced on a Consensus Failure: %v", v))
|
||||
}
|
||||
|
||||
// For those times when we're not sure if we should panic
|
||||
func PanicQ(v interface{}) {
|
||||
panic(Fmt("Paniced questionably: %v", v))
|
||||
}
|
||||
|
||||
+1
-1
@@ -134,7 +134,7 @@ func CRandBytes(numBytes int) []byte {
|
||||
b := make([]byte, numBytes)
|
||||
_, err := crand.Read(b)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
PanicCrisis(err)
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user