mirror of
https://github.com/dolthub/dolt.git
synced 2026-01-29 03:08:47 -06:00
33 lines
631 B
Go
33 lines
631 B
Go
package d
|
|
|
|
import "github.com/attic-labs/noms/Godeps/_workspace/src/github.com/stretchr/testify/assert"
|
|
|
|
// Try calls f() and recovers from any panics caused by using d.Exp. The error generated by the call to d.Exp is returned.
|
|
func Try(f func()) (err error) {
|
|
defer nomsRecover(&err)
|
|
f()
|
|
return
|
|
}
|
|
|
|
type UsageError struct {
|
|
msg string
|
|
}
|
|
|
|
func (e UsageError) Error() string {
|
|
return e.msg
|
|
}
|
|
|
|
func nomsRecover(errp *error) {
|
|
if r := recover(); r != nil {
|
|
if _, ok := r.(UsageError); !ok {
|
|
panic(r)
|
|
}
|
|
*errp = r.(error)
|
|
}
|
|
}
|
|
|
|
func IsUsageError(a *assert.Assertions, f func()) {
|
|
e := Try(f)
|
|
a.IsType(UsageError{}, e)
|
|
}
|