Skip to content

Commit 5de7463

Browse files
author
Dean Karn
authored
Fix source formatting (#13)
* fix source formatting
1 parent 9dfe262 commit 5de7463

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
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-5.1.0-green.svg)
3+
![Project status](https://img.shields.io/badge/version-5.1.1-green.svg)
44
[![Build Status](https://travis-ci.org/go-playground/errors.svg?branch=master)](https://travis-ci.org/go-playground/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://pkg.go.dev/github.com/go-playground/errors/v5)

benchmarks_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ func BenchmarkErrorNew(b *testing.B) {
1010
}
1111
}
1212

13+
func BenchmarkErrorWrap(b *testing.B) {
14+
err := New("base error")
15+
for i := 0; i < b.N; i++ {
16+
_ = Wrap(err, "wrapped error")
17+
}
18+
}
19+
1320
func BenchmarkErrorParallelNew(b *testing.B) {
1421
b.RunParallel(func(pb *testing.PB) {
1522
for pb.Next() {

chain.go

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,19 +76,37 @@ type Link struct {
7676

7777
// formatError prints a single Links error
7878
func (l *Link) formatError(b []byte) []byte {
79+
var funcName string
80+
7981
b = append(b, "source="...)
8082
idx := strings.LastIndexByte(l.Source.Frame.Function, '.')
8183
if idx == -1 {
8284
b = append(b, l.Source.File()...)
8385
} else {
84-
b = append(b, l.Source.Frame.Function[:idx]...)
86+
funcName = l.Source.Frame.Function[idx+1:]
87+
remaining := l.Source.Frame.Function[:idx]
88+
89+
idx = strings.LastIndexByte(remaining, '/')
90+
if idx > -1 {
91+
b = append(b, l.Source.Frame.Function[:idx+1]...)
92+
remaining = l.Source.Frame.Function[idx+1:]
93+
}
94+
95+
idx = strings.IndexByte(remaining, '.')
96+
if idx == -1 {
97+
b = append(b, remaining...)
98+
} else {
99+
b = append(b, remaining[:idx]...)
100+
}
85101
b = append(b, '/')
86102
b = append(b, l.Source.File()...)
87103
}
88104
b = append(b, ':')
89105
b = strconv.AppendInt(b, int64(l.Source.Line()), 10)
90-
b = append(b, ':')
91-
b = append(b, l.Source.Frame.Function[idx+1:]...)
106+
if funcName != "" {
107+
b = append(b, ':')
108+
b = append(b, funcName...)
109+
}
92110
b = append(b, ' ')
93111
b = append(b, "error="...)
94112

0 commit comments

Comments
 (0)