Skip to content

Commit b4ae218

Browse files
author
Dean Karn
committed
Add New function for creating errors
1 parent 9c0defa commit b4ae218

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package errors
22
============
3-
![Project status](https://img.shields.io/badge/version-1.2.0-green.svg)
3+
![Project status](https://img.shields.io/badge/version-1.3.0-green.svg)
44
[![Build Status](https://semaphoreci.com/api/v1/joeybloggs/errors/branches/master/badge.svg)](https://semaphoreci.com/joeybloggs/errors)
55
[![Go Report Card](https://goreportcard.com/badge/github.com/go-playground/errors)](https://goreportcard.com/report/github.com/go-playground/errors)
66
[![GoDoc](https://godoc.org/github.com/go-playground/errors?status.svg)](https://godoc.org/github.com/go-playground/errors)

errors.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package errors
22

3+
import "errors"
4+
35
var (
46
helpers []Helper
57
)
@@ -14,6 +16,10 @@ func RegisterHelper(helper Helper) {
1416
// Wrap encapsulates the error, stores a contextual prefix and automatically obtains
1517
// a stack trace.
1618
func Wrap(err error, prefix string) (w *Wrapped) {
19+
return wrap(err, prefix)
20+
}
21+
22+
func wrap(err error, prefix string) (w *Wrapped) {
1723
var ok bool
1824
if w, ok = err.(*Wrapped); ok {
1925
w.Errors = append(w.Errors, newWrapped(err, prefix))
@@ -73,3 +79,8 @@ func IsErr(err, errType error) bool {
7379
}
7480
return err == errType
7581
}
82+
83+
// New creates an error with the provided text and automatically wraps it with line information.
84+
func New(s string) *Wrapped {
85+
return wrap(errors.New(s), "")
86+
}

stack.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func funcname(name string) string {
114114

115115
func st() string {
116116
s := callers()
117-
f := fr(s, 2)
117+
f := fr(s, 3)
118118
name := fmt.Sprintf("%n", f)
119119
file := fmt.Sprintf("%+s", f)
120120
line := fmt.Sprintf("%d", f)

0 commit comments

Comments
 (0)