Skip to content
This repository was archived by the owner on Dec 1, 2021. It is now read-only.

Commit c1bc528

Browse files
authored
Merge branch 'master' into patch-1
2 parents 6ed0a2e + e19cb69 commit c1bc528

File tree

6 files changed

+129
-96
lines changed

6 files changed

+129
-96
lines changed

.travis.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
language: go
22
go_import_path: github.com/pkg/errors
33
go:
4-
- 1.4.x
5-
- 1.5.x
6-
- 1.6.x
7-
- 1.7.x
8-
- 1.8.x
94
- 1.9.x
105
- 1.10.x
6+
- 1.11.x
117
- tip
128

139
script:
14-
- go test -v ./...
10+
- make check

Makefile

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
PKGS := github.com/pkg/errors
2+
SRCDIRS := $(shell go list -f '{{.Dir}}' $(PKGS))
3+
GO := go
4+
5+
check: test vet gofmt unused misspell unconvert gosimple ineffassign
6+
7+
test:
8+
$(GO) test $(PKGS)
9+
10+
vet: | test
11+
$(GO) vet $(PKGS)
12+
13+
staticcheck:
14+
$(GO) get honnef.co/go/tools/cmd/staticcheck
15+
staticcheck $(PKGS)
16+
17+
unused:
18+
$(GO) get honnef.co/go/tools/cmd/unused
19+
unused -exported $(PKGS)
20+
21+
misspell:
22+
$(GO) get github.com/client9/misspell/cmd/misspell
23+
misspell \
24+
-locale GB \
25+
-error \
26+
*.md *.go
27+
28+
unconvert:
29+
$(GO) get github.com/mdempsky/unconvert
30+
unconvert -v $(PKGS)
31+
32+
gosimple:
33+
$(GO) get honnef.co/go/tools/cmd/gosimple
34+
gosimple $(PKGS)
35+
36+
ineffassign:
37+
$(GO) get github.com/gordonklaus/ineffassign
38+
find $(SRCDIRS) -name '*.go' | xargs ineffassign
39+
40+
pedantic: check unparam errcheck staticcheck
41+
42+
unparam:
43+
$(GO) get mvdan.cc/unparam
44+
unparam ./...
45+
46+
errcheck:
47+
$(GO) get github.com/kisielk/errcheck
48+
errcheck $(PKGS)
49+
50+
gofmt:
51+
@echo Checking code is gofmted
52+
@test -z "$(shell gofmt -s -l -d -e $(SRCDIRS) | tee /dev/stderr)"

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,18 @@ default:
4141

4242
[Read the package documentation for more information](https://godoc.org/github.com/pkg/errors).
4343

44+
## Roadmap
45+
46+
With the upcoming [Go2 error proposals](https://go.googlesource.com/proposal/+/master/design/go2draft.md) this package is moving into maintenance mode. The roadmap for a 1.0 release is as follows:
47+
48+
- 0.9. Remove pre Go 1.9 support, address outstanding pull requests (if possible)
49+
- 1.0. Final release.
50+
4451
## Contributing
4552

46-
We welcome pull requests, bug fixes and issue reports. With that said, the bar for adding new symbols to this package is intentionally set high.
53+
Because of the Go2 errors changes, this package is not accepting proposals for new functionality. With that said, we welcome pull requests, bug fixes and issue reports.
4754

48-
Before proposing a change, please discuss your change by raising an issue.
55+
Before sending a PR, please discuss your change by raising an issue.
4956

5057
## License
5158

errors.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ func WithMessagef(err error, format string, args ...interface{}) error {
229229
}
230230
return &withMessage{
231231
cause: err,
232-
msg: fmt.Sprintf(format, args...),
232+
msg: fmt.Sprintf(format, args...),
233233
}
234234
}
235235

stack.go

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,22 @@ import (
99
)
1010

1111
// Frame represents a program counter inside a stack frame.
12-
type Frame uintptr
13-
14-
// pc returns the program counter for this frame;
15-
// multiple frames may have the same PC value.
16-
func (f Frame) pc() uintptr { return uintptr(f) - 1 }
12+
type Frame runtime.Frame
1713

1814
// file returns the full path to the file that contains the
1915
// function for this Frame's pc.
2016
func (f Frame) file() string {
21-
fn := runtime.FuncForPC(f.pc())
22-
if fn == nil {
17+
file := runtime.Frame(f).File
18+
if file == "" {
2319
return "unknown"
2420
}
25-
file, _ := fn.FileLine(f.pc())
2621
return file
2722
}
2823

2924
// line returns the line number of source code of the
3025
// function for this Frame's pc.
3126
func (f Frame) line() int {
32-
fn := runtime.FuncForPC(f.pc())
33-
if fn == nil {
34-
return 0
35-
}
36-
_, line := fn.FileLine(f.pc())
37-
return line
27+
return runtime.Frame(f).Line
3828
}
3929

4030
// Format formats the frame according to the fmt.Formatter interface.
@@ -54,12 +44,11 @@ func (f Frame) Format(s fmt.State, verb rune) {
5444
case 's':
5545
switch {
5646
case s.Flag('+'):
57-
pc := f.pc()
58-
fn := runtime.FuncForPC(pc)
47+
fn := runtime.Frame(f).Func
5948
if fn == nil {
6049
io.WriteString(s, "unknown")
6150
} else {
62-
file, _ := fn.FileLine(pc)
51+
file := runtime.Frame(f).File
6352
fmt.Fprintf(s, "%s\n\t%s", fn.Name(), file)
6453
}
6554
default:
@@ -68,7 +57,7 @@ func (f Frame) Format(s fmt.State, verb rune) {
6857
case 'd':
6958
fmt.Fprintf(s, "%d", f.line())
7059
case 'n':
71-
name := runtime.FuncForPC(f.pc()).Name()
60+
name := runtime.Frame(f).Function
7261
io.WriteString(s, funcname(name))
7362
case 'v':
7463
f.Format(s, 's')
@@ -114,20 +103,29 @@ func (s *stack) Format(st fmt.State, verb rune) {
114103
case 'v':
115104
switch {
116105
case st.Flag('+'):
117-
for _, pc := range *s {
118-
f := Frame(pc)
119-
fmt.Fprintf(st, "\n%+v", f)
106+
frames := runtime.CallersFrames(*s)
107+
for {
108+
frame, more := frames.Next()
109+
fmt.Fprintf(st, "\n%+v", Frame(frame))
110+
if !more {
111+
break
112+
}
120113
}
121114
}
122115
}
123116
}
124117

125118
func (s *stack) StackTrace() StackTrace {
126-
f := make([]Frame, len(*s))
127-
for i := 0; i < len(f); i++ {
128-
f[i] = Frame((*s)[i])
119+
var st []Frame
120+
frames := runtime.CallersFrames(*s)
121+
for {
122+
frame, more := frames.Next()
123+
st = append(st, Frame(frame))
124+
if !more {
125+
break
126+
}
129127
}
130-
return f
128+
return st
131129
}
132130

133131
func callers() *stack {

0 commit comments

Comments
 (0)