5f33292496
This change just moves the assertion/failure functions from the pkg/util package to pkg/util/contract, so things read a bit nicer (i.e., `contract.Assert(x)` versus `util.Assert(x)`).
31 lines
729 B
Go
31 lines
729 B
Go
// Copyright 2016 Marapongo, Inc. All rights reserved.
|
|
|
|
package contract
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/golang/glog"
|
|
)
|
|
|
|
const failMsg = "A failure has occurred"
|
|
|
|
// Fail unconditionally abandons the process.
|
|
func Fail() {
|
|
failfast(failMsg)
|
|
}
|
|
|
|
// FailM unconditionally abandons the process, logging the given message.
|
|
func FailM(msg string) {
|
|
failfast(fmt.Sprintf("%v: %v", failMsg, msg))
|
|
}
|
|
|
|
// FailMF unconditionally abandons the process, formatting and logging the given message.
|
|
func FailMF(msg string, args ...interface{}) {
|
|
failfast(fmt.Sprintf("%v: %v", failMsg, fmt.Sprintf(msg, args...)))
|
|
}
|
|
|
|
// failfast logs and panics the process in a way that is friendly to debugging.
|
|
func failfast(msg string) {
|
|
glog.Fatal(msg)
|
|
}
|