PageRenderTime 53ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/bettererrors/bettererrors.go

http://github.com/kierdavis/go
Go | 22 lines | 12 code | 4 blank | 6 comment | 0 complexity | 8b8da1bdb7ea53f395a17097c529012d MD5 | raw file
  1. // Package bettererrors provides errors that are initialised with a fmt-compatible format string, so
  2. // that values can be substituted in later.
  3. package bettererrors
  4. import (
  5. "errors"
  6. "fmt"
  7. )
  8. // Type ErrorTemplate represents an error template.
  9. type ErrorTemplate string
  10. // Function New creates and returns a new ErrorTemplate.
  11. func New(format string) (et ErrorTemplate) {
  12. return ErrorTemplate(format)
  13. }
  14. // Function Format runs fmt.Sprintf using the format string specified during creation and the specified
  15. // arguments, then returns the created error.
  16. func (et ErrorTemplate) Format(args ...interface{}) (err error) {
  17. return errors.New(fmt.Sprintf(string(et), args...))
  18. }