-
Notifications
You must be signed in to change notification settings - Fork 1
/
error.go
38 lines (33 loc) · 880 Bytes
/
error.go
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
32
33
34
35
36
37
38
package must
// NoError panics on error.
//
// Use this because test coverage.
func NoError(err error) {
if err != nil {
panic(err)
}
}
// Value panics on error, otherwise returns the first value.
//
// You can use this instead of ignoring errors that never happen by contract.
func Value[T any](out T, err error) T {
if err != nil {
panic(err)
}
return out
}
// V is short for Value, which panics on error, otherwise returns the first value.
func V[T any](out T, err error) T {
return Value(out, err)
}
// Value2 panics on error, otherwise returns the first 2 values.
func Value2[T any, U any](out1 T, out2 U, err error) (T, U) {
if err != nil {
panic(err)
}
return out1, out2
}
// V2 is short for Value2, which panics on error, otherwise returns the first 2 values.
func V2[T any, U any](out1 T, out2 U, err error) (T, U) {
return Value2(out1, out2, err)
}