panic wrapper functions

This commit is contained in:
Ethan Buchman
2015-07-21 10:46:05 -04:00
parent 5983088a32
commit 8e50bf15de
45 changed files with 229 additions and 275 deletions
+1 -1
View File
@@ -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
+27
View File
@@ -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
View File
@@ -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
}