pulumi/pkg/util/assert.go
joeduffy 3a7fa9a983 Use panic for fail-fast
This change switches away from using glog.Fatalf, and instead uses panic,
should a fail-fast arise (due to a call to util.Fail or a failed assertion
by way of util.Assert).  This leads to a better debugging experience no
matter what flags have been passed to glog.  For example, glog.Fatal* seems
to suppress printing stack traces when --logtostderr is supplied.
2016-12-01 11:43:41 -08:00

31 lines
696 B
Go

// Copyright 2016 Marapongo, Inc. All rights reserved.
package util
import (
"fmt"
)
const assertMsg = "An assertion has failed"
// Assert checks a condition and Fails if it is false.
func Assert(cond bool) {
if !cond {
failfast(assertMsg)
}
}
// AssertM checks a condition and FailsMs if it is false, logging the given message.
func AssertM(cond bool, msg string) {
if !cond {
failfast(fmt.Sprintf("%v: %v", assertMsg, msg))
}
}
// AssertMF checks a condition and FailsMFs if it is false, formatting and logging the given message.
func AssertMF(cond bool, msg string, args ...interface{}) {
if !cond {
failfast(fmt.Sprintf("%v: %v", assertMsg, fmt.Sprintf(msg, args...)))
}
}