diff --git a/debug/debug.go b/debug/debug.go index 4ec274a6b..239d6ff53 100644 --- a/debug/debug.go +++ b/debug/debug.go @@ -148,6 +148,8 @@ func Log(tag string, f string, args ...interface{}) { } } +// Break stopts the program if the debug tag is active and the string in tag is +// contained in the DEBUG_BREAK environment variable. func Break(tag string) { // check if breaking is enabled if v, ok := opts.breaks[tag]; !ok || !v { @@ -166,3 +168,12 @@ func Break(tag string) { panic(err) } } + +// BreakIf stopts the program if the debug tag is active and the string in tag +// is contained in the DEBUG_BREAK environment variable and the return value of +// fn is true. +func BreakIf(tag string, fn func() bool) { + if fn() { + Break(tag) + } +} diff --git a/debug/debug_release.go b/debug/debug_release.go index c92bf1e67..3aa6aef49 100644 --- a/debug/debug_release.go +++ b/debug/debug_release.go @@ -5,3 +5,5 @@ package debug func Log(tag string, fmt string, args ...interface{}) {} func Break(string) {} + +func BreakIf(string, func() bool) {}