summaryrefslogtreecommitdiff
path: root/vendor/github.com/authzed/spicedb/pkg/spiceerrors/bug.go
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2025-07-24 17:58:01 -0600
committermo khan <mo@mokhan.ca>2025-07-24 17:58:01 -0600
commit72296119fc9755774719f8f625ad03e0e0ec457a (patch)
treeed236ddee12a20fb55b7cfecf13f62d3a000dcb5 /vendor/github.com/authzed/spicedb/pkg/spiceerrors/bug.go
parenta920a8cfe415858bb2777371a77018599ffed23f (diff)
parenteaa1bd3b8e12934aed06413d75e7482ac58d805a (diff)
Merge branch 'the-spice-must-flow' into 'main'
Add SpiceDB Authorization See merge request gitlab-org/software-supply-chain-security/authorization/sparkled!19
Diffstat (limited to 'vendor/github.com/authzed/spicedb/pkg/spiceerrors/bug.go')
-rw-r--r--vendor/github.com/authzed/spicedb/pkg/spiceerrors/bug.go35
1 files changed, 35 insertions, 0 deletions
diff --git a/vendor/github.com/authzed/spicedb/pkg/spiceerrors/bug.go b/vendor/github.com/authzed/spicedb/pkg/spiceerrors/bug.go
new file mode 100644
index 0000000..7680c33
--- /dev/null
+++ b/vendor/github.com/authzed/spicedb/pkg/spiceerrors/bug.go
@@ -0,0 +1,35 @@
+package spiceerrors
+
+import (
+ "fmt"
+ "os"
+ "strings"
+
+ "github.com/go-errors/errors"
+)
+
+// IsInTests returns true if go test is running
+// Based on: https://stackoverflow.com/a/58945030
+func IsInTests() bool {
+ for _, arg := range os.Args {
+ if strings.HasPrefix(arg, "-test.") {
+ return true
+ }
+ }
+ return false
+}
+
+// MustPanic is a special function for panicing when necessary to violate the linter.
+func MustPanic(format string, args ...any) {
+ panic(fmt.Sprintf(format, args...))
+}
+
+// MustBugf returns an error representing a bug in the system. Will panic if run under testing.
+func MustBugf(format string, args ...any) error {
+ if IsInTests() {
+ panic(fmt.Sprintf(format, args...))
+ }
+
+ e := errors.Errorf(format, args...)
+ return fmt.Errorf("BUG: %s", e.ErrorStack())
+}