Skip to content

Commit d14eb30

Browse files
committed
add Errorf func
1 parent 5326ec1 commit d14eb30

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

error.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cmdkit
33
import (
44
"encoding/json"
55
"errors"
6+
"fmt"
67
)
78

89
// ErrorType signfies a category of errors
@@ -24,6 +25,14 @@ type Error struct {
2425
Code ErrorType
2526
}
2627

28+
// Errorf returns an Error with the given code and format specification
29+
func Errorf(code ErrorType, format string, args ...interface{}) Error {
30+
return Error{
31+
Code: code,
32+
Message: fmt.Sprintf(format, args...),
33+
}
34+
}
35+
2736
func (e Error) Error() string {
2837
return e.Message
2938
}

0 commit comments

Comments
 (0)