dfa5e708fe
This diff rewrites the tor experiment to use measurex "easy" API. To this end, we need to introduce an "easy" measurex API, which basically performs easy measurements returning two pieces of data: 1. the resulting measurement, which is already using the OONI archival data format and is always non-nil 2. a failure (i.e., the pointer to an error string), which is nil on success and points to a string on failure With this change, we should now be able to completely dispose of the original netx API, which was only used by tor. Reference issue: https://github.com/ooni/probe/issues/1688.
30 lines
766 B
Go
30 lines
766 B
Go
// Package runtimex contains runtime extensions. This package is inspired to
|
|
// https://pkg.go.dev/github.com/m-lab/go/rtx, except that it's simpler.
|
|
package runtimex
|
|
|
|
import "fmt"
|
|
|
|
// PanicOnError calls panic() if err is not nil.
|
|
func PanicOnError(err error, message string) {
|
|
if err != nil {
|
|
panic(fmt.Errorf("%s: %w", message, err))
|
|
}
|
|
}
|
|
|
|
// PanicIfFalse calls panic if assertion is false.
|
|
func PanicIfFalse(assertion bool, message string) {
|
|
if !assertion {
|
|
panic(message)
|
|
}
|
|
}
|
|
|
|
// PanicIfTrue calls panic if assertion is true.
|
|
func PanicIfTrue(assertion bool, message string) {
|
|
PanicIfFalse(!assertion, message)
|
|
}
|
|
|
|
// PanicIfNil calls panic if the given interface is nil.
|
|
func PanicIfNil(v interface{}, message string) {
|
|
PanicIfTrue(v == nil, message)
|
|
}
|