pulumi/pkg/util/contract/fail.go
joeduffy 5f33292496 Move assertion/failure functions
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)`).
2017-01-15 14:26:48 -08:00

32 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)
}