Skip to content

Commit

Permalink
Fix source formatting (#13)
Browse files Browse the repository at this point in the history
* fix source formatting
  • Loading branch information
deankarn committed Jul 7, 2020
1 parent 9dfe262 commit 5de7463
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package errors
============
![Project status](https://img.shields.io/badge/version-5.1.0-green.svg)
![Project status](https://img.shields.io/badge/version-5.1.1-green.svg)
[![Build Status](https://travis-ci.org/go-playground/errors.svg?branch=master)](https://travis-ci.org/go-playground/errors)
[![Go Report Card](https://goreportcard.com/badge/github.com/go-playground/errors)](https://goreportcard.com/report/github.com/go-playground/errors)
[![GoDoc](https://godoc.org/github.com/go-playground/errors?status.svg)](https://pkg.go.dev/github.com/go-playground/errors/v5)
Expand Down
7 changes: 7 additions & 0 deletions benchmarks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ func BenchmarkErrorNew(b *testing.B) {
}
}

func BenchmarkErrorWrap(b *testing.B) {
err := New("base error")
for i := 0; i < b.N; i++ {
_ = Wrap(err, "wrapped error")
}
}

func BenchmarkErrorParallelNew(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
Expand Down
24 changes: 21 additions & 3 deletions chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,37 @@ type Link struct {

// formatError prints a single Links error
func (l *Link) formatError(b []byte) []byte {
var funcName string

b = append(b, "source="...)
idx := strings.LastIndexByte(l.Source.Frame.Function, '.')
if idx == -1 {
b = append(b, l.Source.File()...)
} else {
b = append(b, l.Source.Frame.Function[:idx]...)
funcName = l.Source.Frame.Function[idx+1:]
remaining := l.Source.Frame.Function[:idx]

idx = strings.LastIndexByte(remaining, '/')
if idx > -1 {
b = append(b, l.Source.Frame.Function[:idx+1]...)
remaining = l.Source.Frame.Function[idx+1:]
}

idx = strings.IndexByte(remaining, '.')
if idx == -1 {
b = append(b, remaining...)
} else {
b = append(b, remaining[:idx]...)
}
b = append(b, '/')
b = append(b, l.Source.File()...)
}
b = append(b, ':')
b = strconv.AppendInt(b, int64(l.Source.Line()), 10)
b = append(b, ':')
b = append(b, l.Source.Frame.Function[idx+1:]...)
if funcName != "" {
b = append(b, ':')
b = append(b, funcName...)
}
b = append(b, ' ')
b = append(b, "error="...)

Expand Down

0 comments on commit 5de7463

Please sign in to comment.