mirror of
https://github.com/dolthub/dolt.git
synced 2026-02-05 10:31:30 -06:00
We can still get useful error messages out of d.Try without specifically wrapping every single thing that might throw a noms UsageError, so do so. The code is cleaner. Towards issue #176
26 lines
442 B
Go
26 lines
442 B
Go
package d
|
|
|
|
// 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)
|
|
}
|
|
}
|