You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.3 KiB

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