summaryrefslogtreecommitdiff
path: root/vendor/github.com/authzed/spicedb/pkg/spiceerrors/assert_on.go
blob: a21414791eb16ec3c2249588f1c5a708463e051f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//go:build ci
// +build ci

package spiceerrors

import (
	"fmt"
	"runtime"
)

const DebugAssertionsEnabled = true

// DebugAssert panics if the condition is false in CI builds.
func DebugAssert(condition func() bool, format string, args ...any) {
	if !condition() {
		panic(fmt.Sprintf(format, args...))
	}
}

// DebugAssertNotNil panics if the object is nil in CI builds.
func DebugAssertNotNil(obj any, format string, args ...any) {
	if obj == nil {
		panic(fmt.Sprintf(format, args...))
	}
}

// SetFinalizerForDebugging sets a finalizer on the object for debugging purposes
// in CI builds.
func SetFinalizerForDebugging[T any](obj interface{}, finalizer func(obj T)) {
	runtime.SetFinalizer(obj, finalizer)
}