aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRunxi Yu <me@runxiyu.org>2025-02-11 23:32:43 +0800
committerRunxi Yu <me@runxiyu.org>2025-02-11 23:32:43 +0800
commit8946fae17bd05520d7237dc077d48d83d5471fdd (patch)
tree0269e02372cd06f5224170033316f73fb4abc77a
parentmisc: sanitize_path should be exported (diff)
downloadgo-lindenii-common-8946fae17bd05520d7237dc077d48d83d5471fdd.tar.gz
go-lindenii-common-8946fae17bd05520d7237dc077d48d83d5471fdd.tar.zst
go-lindenii-common-8946fae17bd05520d7237dc077d48d83d5471fdd.zip
misc: First_or_panic
-rw-r--r--misc/errors.go7
1 files changed, 7 insertions, 0 deletions
diff --git a/misc/errors.go b/misc/errors.go
index 5c22a20..8434637 100644
--- a/misc/errors.go
+++ b/misc/errors.go
@@ -5,3 +5,10 @@ import "fmt"
func Wrap_one_error(a error, b error) error {
return fmt.Errorf("%w: %w", a, b)
}
+
+func First_or_panic[T any](v T, err error) T {
+ if err != nil {
+ panic(err)
+ }
+ return v
+}