Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Kochie <superq@gmail.com>2018-10-31 01:14:35 +0300
committerBen Kochie <superq@gmail.com>2018-10-31 10:13:33 +0300
commit046e11d71a19abdb077202312b6d9e4e7e094db2 (patch)
treedda0c4469fa2f8d4fff48ff4126312c00a5040ac
parent4265416dbd578313586e93554498ac2caff7cf73 (diff)
Update vendor github.com/getsentry/raven-go@v0
-rw-r--r--NOTICE25
-rw-r--r--vendor/github.com/getsentry/raven-go/README.md6
-rw-r--r--vendor/github.com/getsentry/raven-go/client.go214
-rw-r--r--vendor/github.com/getsentry/raven-go/errors.go60
-rw-r--r--vendor/github.com/getsentry/raven-go/http.go23
-rw-r--r--vendor/github.com/getsentry/raven-go/stacktrace.go103
-rw-r--r--vendor/github.com/pkg/errors/LICENSE23
-rw-r--r--vendor/github.com/pkg/errors/README.md52
-rw-r--r--vendor/github.com/pkg/errors/appveyor.yml32
-rw-r--r--vendor/github.com/pkg/errors/errors.go282
-rw-r--r--vendor/github.com/pkg/errors/stack.go147
-rw-r--r--vendor/vendor.json16
12 files changed, 902 insertions, 81 deletions
diff --git a/NOTICE b/NOTICE
index 62f71c92e..f9a541667 100644
--- a/NOTICE
+++ b/NOTICE
@@ -862,6 +862,31 @@ LICENSE - gitlab.com/gitlab-org/gitaly/vendor/github.com/matttproud/golang_proto
NOTICE - gitlab.com/gitlab-org/gitaly/vendor/github.com/matttproud/golang_protobuf_extensions
Copyright 2012 Matt T. Proud (matt.proud@gmail.com)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+LICENSE - gitlab.com/gitlab-org/gitaly/vendor/github.com/pkg/errors
+Copyright (c) 2015, Dave Cheney <dave@cheney.net>
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+* Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+* Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
LICENSE - gitlab.com/gitlab-org/gitaly/vendor/github.com/pmezard/go-difflib
Copyright (c) 2013, Patrick Mezard
All rights reserved.
diff --git a/vendor/github.com/getsentry/raven-go/README.md b/vendor/github.com/getsentry/raven-go/README.md
index 5ea29a0a0..2357ec7dc 100644
--- a/vendor/github.com/getsentry/raven-go/README.md
+++ b/vendor/github.com/getsentry/raven-go/README.md
@@ -1,4 +1,8 @@
-# raven [![Build Status](https://travis-ci.org/getsentry/raven-go.png?branch=master)](https://travis-ci.org/getsentry/raven-go)
+# raven
+
+[![Build Status](https://api.travis-ci.org/getsentry/raven-go.svg?branch=master)](https://travis-ci.org/getsentry/raven-go)
+[![Go Report Card](https://goreportcard.com/badge/github.com/getsentry/raven-go)](https://goreportcard.com/report/github.com/getsentry/raven-go)
+[![GoDoc](https://godoc.org/github.com/getsentry/raven-go?status.svg)](https://godoc.org/github.com/getsentry/raven-go)
raven is a Go client for the [Sentry](https://github.com/getsentry/sentry)
event/error logging system.
diff --git a/vendor/github.com/getsentry/raven-go/client.go b/vendor/github.com/getsentry/raven-go/client.go
index 07ed9c5d8..a2c9a6c35 100644
--- a/vendor/github.com/getsentry/raven-go/client.go
+++ b/vendor/github.com/getsentry/raven-go/client.go
@@ -14,6 +14,7 @@ import (
"io"
"io/ioutil"
"log"
+ mrand "math/rand"
"net/http"
"net/url"
"os"
@@ -24,6 +25,7 @@ import (
"time"
"github.com/certifi/gocertifi"
+ pkgErrors "github.com/pkg/errors"
)
const (
@@ -35,8 +37,8 @@ var (
ErrPacketDropped = errors.New("raven: packet dropped")
ErrUnableToUnmarshalJSON = errors.New("raven: unable to unmarshal JSON")
ErrMissingUser = errors.New("raven: dsn missing public key and/or password")
- ErrMissingPrivateKey = errors.New("raven: dsn missing private key")
ErrMissingProjectID = errors.New("raven: dsn missing project id")
+ ErrInvalidSampleRate = errors.New("raven: sample rate should be between 0 and 1")
)
type Severity string
@@ -66,6 +68,11 @@ func (timestamp *Timestamp) UnmarshalJSON(data []byte) error {
return nil
}
+func (timestamp Timestamp) Format(format string) string {
+ t := time.Time(timestamp)
+ return t.Format(format)
+}
+
// An Interface is a Sentry interface that will be serialized as JSON.
// It must implement json.Marshaler or use json struct tags.
type Interface interface {
@@ -81,6 +88,8 @@ type Transport interface {
Send(url, authHeader string, packet *Packet) error
}
+type Extra map[string]interface{}
+
type outgoingPacket struct {
packet *Packet
ch chan error
@@ -147,27 +156,37 @@ type Packet struct {
Logger string `json:"logger"`
// Optional
- Platform string `json:"platform,omitempty"`
- Culprit string `json:"culprit,omitempty"`
- ServerName string `json:"server_name,omitempty"`
- Release string `json:"release,omitempty"`
- Environment string `json:"environment,omitempty"`
- Tags Tags `json:"tags,omitempty"`
- Modules map[string]string `json:"modules,omitempty"`
- Fingerprint []string `json:"fingerprint,omitempty"`
- Extra map[string]interface{} `json:"extra,omitempty"`
+ Platform string `json:"platform,omitempty"`
+ Culprit string `json:"culprit,omitempty"`
+ ServerName string `json:"server_name,omitempty"`
+ Release string `json:"release,omitempty"`
+ Environment string `json:"environment,omitempty"`
+ Tags Tags `json:"tags,omitempty"`
+ Modules map[string]string `json:"modules,omitempty"`
+ Fingerprint []string `json:"fingerprint,omitempty"`
+ Extra Extra `json:"extra,omitempty"`
Interfaces []Interface `json:"-"`
}
// NewPacket constructs a packet with the specified message and interfaces.
func NewPacket(message string, interfaces ...Interface) *Packet {
- extra := map[string]interface{}{
- "runtime.Version": runtime.Version(),
- "runtime.NumCPU": runtime.NumCPU(),
- "runtime.GOMAXPROCS": runtime.GOMAXPROCS(0), // 0 just returns the current value
- "runtime.NumGoroutine": runtime.NumGoroutine(),
+ extra := Extra{}
+ setExtraDefaults(extra)
+ return &Packet{
+ Message: message,
+ Interfaces: interfaces,
+ Extra: extra,
}
+}
+
+// NewPacketWithExtra constructs a packet with the specified message, extra information, and interfaces.
+func NewPacketWithExtra(message string, extra Extra, interfaces ...Interface) *Packet {
+ if extra == nil {
+ extra = Extra{}
+ }
+ setExtraDefaults(extra)
+
return &Packet{
Message: message,
Interfaces: interfaces,
@@ -175,6 +194,14 @@ func NewPacket(message string, interfaces ...Interface) *Packet {
}
}
+func setExtraDefaults(extra Extra) Extra {
+ extra["runtime.Version"] = runtime.Version()
+ extra["runtime.NumCPU"] = runtime.NumCPU()
+ extra["runtime.GOMAXPROCS"] = runtime.GOMAXPROCS(0) // 0 just returns the current value
+ extra["runtime.NumGoroutine"] = runtime.NumGoroutine()
+ return extra
+}
+
// Init initializes required fields in a packet. It is typically called by
// Client.Send/Report automatically.
func (packet *Packet) Init(project string) error {
@@ -268,9 +295,9 @@ type context struct {
tags map[string]string
}
-func (c *context) SetUser(u *User) { c.user = u }
-func (c *context) SetHttp(h *Http) { c.http = h }
-func (c *context) SetTags(t map[string]string) {
+func (c *context) setUser(u *User) { c.user = u }
+func (c *context) setHttp(h *Http) { c.http = h }
+func (c *context) setTags(t map[string]string) {
if c.tags == nil {
c.tags = make(map[string]string)
}
@@ -278,7 +305,7 @@ func (c *context) SetTags(t map[string]string) {
c.tags[k] = v
}
}
-func (c *context) Clear() {
+func (c *context) clear() {
c.user = nil
c.http = nil
c.tags = nil
@@ -317,7 +344,7 @@ func newTransport() Transport {
} else {
t.Client = &http.Client{
Transport: &http.Transport{
- Proxy: http.ProxyFromEnvironment,
+ Proxy: http.ProxyFromEnvironment,
TLSClientConfig: &tls.Config{RootCAs: rootCAs},
},
}
@@ -327,12 +354,15 @@ func newTransport() Transport {
func newClient(tags map[string]string) *Client {
client := &Client{
- Transport: newTransport(),
- Tags: tags,
- context: &context{},
- queue: make(chan *outgoingPacket, MaxQueueBuffer),
+ Transport: newTransport(),
+ Tags: tags,
+ context: &context{},
+ sampleRate: 1.0,
+ queue: make(chan *outgoingPacket, MaxQueueBuffer),
}
client.SetDSN(os.Getenv("SENTRY_DSN"))
+ client.SetRelease(os.Getenv("SENTRY_RELEASE"))
+ client.SetEnvironment(os.Getenv("SENTRY_ENVIRONMENT"))
return client
}
@@ -371,12 +401,17 @@ type Client struct {
// Context that will get appending to all packets
context *context
- mu sync.RWMutex
- url string
- projectID string
- authHeader string
- release string
- environment string
+ mu sync.RWMutex
+ url string
+ projectID string
+ authHeader string
+ release string
+ environment string
+ sampleRate float32
+
+ // default logger name (leave empty for 'root')
+ defaultLoggerName string
+
includePaths []string
ignoreErrorsRegexp *regexp.Regexp
queue chan *outgoingPacket
@@ -435,10 +470,7 @@ func (client *Client) SetDSN(dsn string) error {
return ErrMissingUser
}
publicKey := uri.User.Username()
- secretKey, ok := uri.User.Password()
- if !ok {
- return ErrMissingPrivateKey
- }
+ secretKey, hasSecretKey := uri.User.Password()
uri.User = nil
if idx := strings.LastIndex(uri.Path, "/"); idx != -1 {
@@ -451,7 +483,11 @@ func (client *Client) SetDSN(dsn string) error {
client.url = uri.String()
- client.authHeader = fmt.Sprintf("Sentry sentry_version=4, sentry_key=%s, sentry_secret=%s", publicKey, secretKey)
+ if hasSecretKey {
+ client.authHeader = fmt.Sprintf("Sentry sentry_version=4, sentry_key=%s, sentry_secret=%s", publicKey, secretKey)
+ } else {
+ client.authHeader = fmt.Sprintf("Sentry sentry_version=4, sentry_key=%s", publicKey)
+ }
return nil
}
@@ -473,12 +509,39 @@ func (client *Client) SetEnvironment(environment string) {
client.environment = environment
}
+// SetDefaultLoggerName sets the default logger name.
+func (client *Client) SetDefaultLoggerName(name string) {
+ client.mu.Lock()
+ defer client.mu.Unlock()
+ client.defaultLoggerName = name
+}
+
+// SetSampleRate sets how much sampling we want on client side
+func (client *Client) SetSampleRate(rate float32) error {
+ client.mu.Lock()
+ defer client.mu.Unlock()
+
+ if rate < 0 || rate > 1 {
+ return ErrInvalidSampleRate
+ }
+ client.sampleRate = rate
+ return nil
+}
+
// SetRelease sets the "release" tag on the default *Client
func SetRelease(release string) { DefaultClient.SetRelease(release) }
// SetEnvironment sets the "environment" tag on the default *Client
func SetEnvironment(environment string) { DefaultClient.SetEnvironment(environment) }
+// SetDefaultLoggerName sets the "defaultLoggerName" on the default *Client
+func SetDefaultLoggerName(name string) {
+ DefaultClient.SetDefaultLoggerName(name)
+}
+
+// SetSampleRate sets the "sample rate" on the degault *Client
+func SetSampleRate(rate float32) error { return DefaultClient.SetSampleRate(rate) }
+
func (client *Client) worker() {
for outgoingPacket := range client.queue {
@@ -503,6 +566,15 @@ func (client *Client) Capture(packet *Packet, captureTags map[string]string) (ev
return
}
+ if client.sampleRate < 1.0 && mrand.Float32() > client.sampleRate {
+ return
+ }
+
+ if packet == nil {
+ close(ch)
+ return
+ }
+
if client.shouldExcludeErr(packet.Message) {
return
}
@@ -515,15 +587,21 @@ func (client *Client) Capture(packet *Packet, captureTags map[string]string) (ev
// Merge capture tags and client tags
packet.AddTags(captureTags)
packet.AddTags(client.Tags)
- packet.AddTags(client.context.tags)
// Initialize any required packet fields
client.mu.RLock()
+ packet.AddTags(client.context.tags)
projectID := client.projectID
release := client.release
environment := client.environment
+ defaultLoggerName := client.defaultLoggerName
client.mu.RUnlock()
+ // set the global logger name on the packet if we must
+ if packet.Logger == "" && defaultLoggerName != "" {
+ packet.Logger = defaultLoggerName
+ }
+
err := packet.Init(projectID)
if err != nil {
ch <- err
@@ -531,8 +609,13 @@ func (client *Client) Capture(packet *Packet, captureTags map[string]string) (ev
return
}
- packet.Release = release
- packet.Environment = environment
+ if packet.Release == "" {
+ packet.Release = release
+ }
+
+ if packet.Environment == "" {
+ packet.Environment = environment
+ }
outgoingPacket := &outgoingPacket{packet, ch}
@@ -596,7 +679,9 @@ func (client *Client) CaptureMessageAndWait(message string, tags map[string]stri
packet := NewPacket(message, append(append(interfaces, client.context.interfaces()...), &Message{message, nil})...)
eventID, ch := client.Capture(packet, tags)
- <-ch
+ if eventID != "" {
+ <-ch
+ }
return eventID
}
@@ -613,11 +698,18 @@ func (client *Client) CaptureError(err error, tags map[string]string, interfaces
return ""
}
+ if err == nil {
+ return ""
+ }
+
if client.shouldExcludeErr(err.Error()) {
return ""
}
- packet := NewPacket(err.Error(), append(append(interfaces, client.context.interfaces()...), NewException(err, NewStacktrace(1, 3, client.includePaths)))...)
+ extra := extractExtra(err)
+ cause := pkgErrors.Cause(err)
+
+ packet := NewPacketWithExtra(err.Error(), extra, append(append(interfaces, client.context.interfaces()...), NewException(cause, GetOrNewStacktrace(cause, 1, 3, client.includePaths)))...)
eventID, _ := client.Capture(packet, tags)
return eventID
@@ -639,9 +731,14 @@ func (client *Client) CaptureErrorAndWait(err error, tags map[string]string, int
return ""
}
- packet := NewPacket(err.Error(), append(append(interfaces, client.context.interfaces()...), NewException(err, NewStacktrace(1, 3, client.includePaths)))...)
+ extra := extractExtra(err)
+ cause := pkgErrors.Cause(err)
+
+ packet := NewPacketWithExtra(err.Error(), extra, append(append(interfaces, client.context.interfaces()...), NewException(cause, GetOrNewStacktrace(cause, 1, 3, client.includePaths)))...)
eventID, ch := client.Capture(packet, tags)
- <-ch
+ if eventID != "" {
+ <-ch
+ }
return eventID
}
@@ -717,7 +814,9 @@ func (client *Client) CapturePanicAndWait(f func(), tags map[string]string, inte
var ch chan error
errorID, ch = client.Capture(packet, tags)
- <-ch
+ if errorID != "" {
+ <-ch
+ }
}()
f()
@@ -788,10 +887,29 @@ func (client *Client) SetIncludePaths(p []string) {
client.includePaths = p
}
-func (c *Client) SetUserContext(u *User) { c.context.SetUser(u) }
-func (c *Client) SetHttpContext(h *Http) { c.context.SetHttp(h) }
-func (c *Client) SetTagsContext(t map[string]string) { c.context.SetTags(t) }
-func (c *Client) ClearContext() { c.context.Clear() }
+func (c *Client) SetUserContext(u *User) {
+ c.mu.Lock()
+ defer c.mu.Unlock()
+ c.context.setUser(u)
+}
+
+func (c *Client) SetHttpContext(h *Http) {
+ c.mu.Lock()
+ defer c.mu.Unlock()
+ c.context.setHttp(h)
+}
+
+func (c *Client) SetTagsContext(t map[string]string) {
+ c.mu.Lock()
+ defer c.mu.Unlock()
+ c.context.setTags(t)
+}
+
+func (c *Client) ClearContext() {
+ c.mu.Lock()
+ defer c.mu.Unlock()
+ c.context.clear()
+}
func SetUserContext(u *User) { DefaultClient.SetUserContext(u) }
func SetHttpContext(h *Http) { DefaultClient.SetHttpContext(h) }
@@ -827,7 +945,7 @@ func (t *HTTPTransport) Send(url, authHeader string, packet *Packet) error {
io.Copy(ioutil.Discard, res.Body)
res.Body.Close()
if res.StatusCode != 200 {
- return fmt.Errorf("raven: got http status %d", res.StatusCode)
+ return fmt.Errorf("raven: got http status %d - x-sentry-error: %s", res.StatusCode, res.Header.Get("X-Sentry-Error"))
}
return nil
}
diff --git a/vendor/github.com/getsentry/raven-go/errors.go b/vendor/github.com/getsentry/raven-go/errors.go
new file mode 100644
index 000000000..5e5727043
--- /dev/null
+++ b/vendor/github.com/getsentry/raven-go/errors.go
@@ -0,0 +1,60 @@
+package raven
+
+type causer interface {
+ Cause() error
+}
+
+type errWrappedWithExtra struct {
+ err error
+ extraInfo map[string]interface{}
+}
+
+func (ewx *errWrappedWithExtra) Error() string {
+ return ewx.err.Error()
+}
+
+func (ewx *errWrappedWithExtra) Cause() error {
+ return ewx.err
+}
+
+func (ewx *errWrappedWithExtra) ExtraInfo() Extra {
+ return ewx.extraInfo
+}
+
+// Adds extra data to an error before reporting to Sentry
+func WrapWithExtra(err error, extraInfo map[string]interface{}) error {
+ return &errWrappedWithExtra{
+ err: err,
+ extraInfo: extraInfo,
+ }
+}
+
+type ErrWithExtra interface {
+ Error() string
+ Cause() error
+ ExtraInfo() Extra
+}
+
+// Iteratively fetches all the Extra data added to an error,
+// and it's underlying errors. Extra data defined first is
+// respected, and is not overridden when extracting.
+func extractExtra(err error) Extra {
+ extra := Extra{}
+
+ currentErr := err
+ for currentErr != nil {
+ if errWithExtra, ok := currentErr.(ErrWithExtra); ok {
+ for k, v := range errWithExtra.ExtraInfo() {
+ extra[k] = v
+ }
+ }
+
+ if errWithCause, ok := currentErr.(causer); ok {
+ currentErr = errWithCause.Cause()
+ } else {
+ currentErr = nil
+ }
+ }
+
+ return extra
+}
diff --git a/vendor/github.com/getsentry/raven-go/http.go b/vendor/github.com/getsentry/raven-go/http.go
index 32107b883..ae8f47234 100644
--- a/vendor/github.com/getsentry/raven-go/http.go
+++ b/vendor/github.com/getsentry/raven-go/http.go
@@ -28,6 +28,7 @@ func NewHttp(req *http.Request) *Http {
for k, v := range req.Header {
h.Headers[k] = strings.Join(v, ",")
}
+ h.Headers["Host"] = req.Host
return h
}
@@ -68,17 +69,31 @@ func (h *Http) Class() string { return "request" }
// ...
// }))
func RecoveryHandler(handler func(http.ResponseWriter, *http.Request)) func(http.ResponseWriter, *http.Request) {
- return func(w http.ResponseWriter, r *http.Request) {
+ return Recoverer(http.HandlerFunc(handler)).ServeHTTP
+}
+
+// Recovery handler to wrap the stdlib net/http Mux.
+// Example:
+// mux := http.NewServeMux
+// ...
+// http.Handle("/", raven.Recoverer(mux))
+func Recoverer(handler http.Handler) http.Handler {
+ return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
defer func() {
if rval := recover(); rval != nil {
debug.PrintStack()
rvalStr := fmt.Sprint(rval)
- packet := NewPacket(rvalStr, NewException(errors.New(rvalStr), NewStacktrace(2, 3, nil)), NewHttp(r))
+ var packet *Packet
+ if err, ok := rval.(error); ok {
+ packet = NewPacket(rvalStr, NewException(errors.New(rvalStr), GetOrNewStacktrace(err, 2, 3, nil)), NewHttp(r))
+ } else {
+ packet = NewPacket(rvalStr, NewException(errors.New(rvalStr), NewStacktrace(2, 3, nil)), NewHttp(r))
+ }
Capture(packet, nil)
w.WriteHeader(http.StatusInternalServerError)
}
}()
- handler(w, r)
- }
+ handler.ServeHTTP(w, r)
+ })
}
diff --git a/vendor/github.com/getsentry/raven-go/stacktrace.go b/vendor/github.com/getsentry/raven-go/stacktrace.go
index 114c5f97b..4db79b42f 100644
--- a/vendor/github.com/getsentry/raven-go/stacktrace.go
+++ b/vendor/github.com/getsentry/raven-go/stacktrace.go
@@ -9,10 +9,13 @@ import (
"bytes"
"go/build"
"io/ioutil"
+ "net/url"
"path/filepath"
"runtime"
"strings"
"sync"
+
+ "github.com/pkg/errors"
)
// https://docs.getsentry.com/hosted/clientdev/interfaces/#failure-interfaces
@@ -49,6 +52,34 @@ type StacktraceFrame struct {
InApp bool `json:"in_app"`
}
+// Try to get stacktrace from err as an interface of github.com/pkg/errors, or else NewStacktrace()
+func GetOrNewStacktrace(err error, skip int, context int, appPackagePrefixes []string) *Stacktrace {
+ stacktracer, errHasStacktrace := err.(interface {
+ StackTrace() errors.StackTrace
+ })
+ if errHasStacktrace {
+ var frames []*StacktraceFrame
+ for _, f := range stacktracer.StackTrace() {
+ pc := uintptr(f) - 1
+ fn := runtime.FuncForPC(pc)
+ var file string
+ var line int
+ if fn != nil {
+ file, line = fn.FileLine(pc)
+ } else {
+ file = "unknown"
+ }
+ frame := NewStacktraceFrame(pc, file, line, context, appPackagePrefixes)
+ if frame != nil {
+ frames = append([]*StacktraceFrame{frame}, frames...)
+ }
+ }
+ return &Stacktrace{Frames: frames}
+ } else {
+ return NewStacktrace(skip+1, context, appPackagePrefixes)
+ }
+}
+
// Intialize and populate a new stacktrace, skipping skip frames.
//
// context is the number of surrounding lines that should be included for context.
@@ -113,7 +144,7 @@ func NewStacktraceFrame(pc uintptr, file string, line, context int, appPackagePr
}
if context > 0 {
- contextLines, lineIdx := fileContext(file, line, context)
+ contextLines, lineIdx := sourceCodeLoader.Load(file, line, context)
if len(contextLines) > 0 {
for i, line := range contextLines {
switch {
@@ -127,7 +158,7 @@ func NewStacktraceFrame(pc uintptr, file string, line, context int, appPackagePr
}
}
} else if context == -1 {
- contextLine, _ := fileContext(file, line, 0)
+ contextLine, _ := sourceCodeLoader.Load(file, line, 0)
if len(contextLine) > 0 {
frame.ContextLine = string(contextLine[0])
}
@@ -136,43 +167,65 @@ func NewStacktraceFrame(pc uintptr, file string, line, context int, appPackagePr
}
// Retrieve the name of the package and function containing the PC.
-func functionName(pc uintptr) (pack string, name string) {
+func functionName(pc uintptr) (string, string) {
fn := runtime.FuncForPC(pc)
if fn == nil {
- return
- }
- name = fn.Name()
- // We get this:
- // runtime/debug.*T·ptrmethod
- // and want this:
- // pack = runtime/debug
- // name = *T.ptrmethod
- if idx := strings.LastIndex(name, "."); idx != -1 {
- pack = name[:idx]
- name = name[idx+1:]
- }
- name = strings.Replace(name, "·", ".", -1)
- return
+ return "", ""
+ }
+
+ return splitFunctionName(fn.Name())
}
-var fileCacheLock sync.Mutex
-var fileCache = make(map[string][][]byte)
+func splitFunctionName(name string) (string, string) {
+ var pack string
+
+ if pos := strings.LastIndex(name, "/"); pos != -1 {
+ pack = name[:pos+1]
+ name = name[pos+1:]
+ }
+
+ if pos := strings.Index(name, "."); pos != -1 {
+ pack += name[:pos]
+ name = name[pos+1:]
+ }
+
+ if p, err := url.QueryUnescape(pack); err == nil {
+ pack = p
+ }
+
+ return pack, name
+}
+
+type SourceCodeLoader interface {
+ Load(filename string, line, context int) ([][]byte, int)
+}
+
+var sourceCodeLoader SourceCodeLoader = &fsLoader{cache: make(map[string][][]byte)}
+
+func SetSourceCodeLoader(loader SourceCodeLoader) {
+ sourceCodeLoader = loader
+}
+
+type fsLoader struct {
+ mu sync.Mutex
+ cache map[string][][]byte
+}
-func fileContext(filename string, line, context int) ([][]byte, int) {
- fileCacheLock.Lock()
- defer fileCacheLock.Unlock()
- lines, ok := fileCache[filename]
+func (fs *fsLoader) Load(filename string, line, context int) ([][]byte, int) {
+ fs.mu.Lock()
+ defer fs.mu.Unlock()
+ lines, ok := fs.cache[filename]
if !ok {
data, err := ioutil.ReadFile(filename)
if err != nil {
// cache errors as nil slice: code below handles it correctly
// otherwise when missing the source or running as a different user, we try
// reading the file on each error which is unnecessary
- fileCache[filename] = nil
+ fs.cache[filename] = nil
return nil, 0
}
lines = bytes.Split(data, []byte{'\n'})
- fileCache[filename] = lines
+ fs.cache[filename] = lines
}
if lines == nil {
diff --git a/vendor/github.com/pkg/errors/LICENSE b/vendor/github.com/pkg/errors/LICENSE
new file mode 100644
index 000000000..835ba3e75
--- /dev/null
+++ b/vendor/github.com/pkg/errors/LICENSE
@@ -0,0 +1,23 @@
+Copyright (c) 2015, Dave Cheney <dave@cheney.net>
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+* Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+* Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/vendor/github.com/pkg/errors/README.md b/vendor/github.com/pkg/errors/README.md
new file mode 100644
index 000000000..6483ba2af
--- /dev/null
+++ b/vendor/github.com/pkg/errors/README.md
@@ -0,0 +1,52 @@
+# errors [![Travis-CI](https://travis-ci.org/pkg/errors.svg)](https://travis-ci.org/pkg/errors) [![AppVeyor](https://ci.appveyor.com/api/projects/status/b98mptawhudj53ep/branch/master?svg=true)](https://ci.appveyor.com/project/davecheney/errors/branch/master) [![GoDoc](https://godoc.org/github.com/pkg/errors?status.svg)](http://godoc.org/github.com/pkg/errors) [![Report card](https://goreportcard.com/badge/github.com/pkg/errors)](https://goreportcard.com/report/github.com/pkg/errors) [![Sourcegraph](https://sourcegraph.com/github.com/pkg/errors/-/badge.svg)](https://sourcegraph.com/github.com/pkg/errors?badge)
+
+Package errors provides simple error handling primitives.
+
+`go get github.com/pkg/errors`
+
+The traditional error handling idiom in Go is roughly akin to
+```go
+if err != nil {
+ return err
+}
+```
+which applied recursively up the call stack results in error reports without context or debugging information. The errors package allows programmers to add context to the failure path in their code in a way that does not destroy the original value of the error.
+
+## Adding context to an error
+
+The errors.Wrap function returns a new error that adds context to the original error. For example
+```go
+_, err := ioutil.ReadAll(r)
+if err != nil {
+ return errors.Wrap(err, "read failed")
+}
+```
+## Retrieving the cause of an error
+
+Using `errors.Wrap` constructs a stack of errors, adding context to the preceding error. Depending on the nature of the error it may be necessary to reverse the operation of errors.Wrap to retrieve the original error for inspection. Any error value which implements this interface can be inspected by `errors.Cause`.
+```go
+type causer interface {
+ Cause() error
+}
+```
+`errors.Cause` will recursively retrieve the topmost error which does not implement `causer`, which is assumed to be the original cause. For example:
+```go
+switch err := errors.Cause(err).(type) {
+case *MyError:
+ // handle specifically
+default:
+ // unknown error
+}
+```
+
+[Read the package documentation for more information](https://godoc.org/github.com/pkg/errors).
+
+## Contributing
+
+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.
+
+Before proposing a change, please discuss your change by raising an issue.
+
+## License
+
+BSD-2-Clause
diff --git a/vendor/github.com/pkg/errors/appveyor.yml b/vendor/github.com/pkg/errors/appveyor.yml
new file mode 100644
index 000000000..a932eade0
--- /dev/null
+++ b/vendor/github.com/pkg/errors/appveyor.yml
@@ -0,0 +1,32 @@
+version: build-{build}.{branch}
+
+clone_folder: C:\gopath\src\github.com\pkg\errors
+shallow_clone: true # for startup speed
+
+environment:
+ GOPATH: C:\gopath
+
+platform:
+ - x64
+
+# http://www.appveyor.com/docs/installed-software
+install:
+ # some helpful output for debugging builds
+ - go version
+ - go env
+ # pre-installed MinGW at C:\MinGW is 32bit only
+ # but MSYS2 at C:\msys64 has mingw64
+ - set PATH=C:\msys64\mingw64\bin;%PATH%
+ - gcc --version
+ - g++ --version
+
+build_script:
+ - go install -v ./...
+
+test_script:
+ - set PATH=C:\gopath\bin;%PATH%
+ - go test -v ./...
+
+#artifacts:
+# - path: '%GOPATH%\bin\*.exe'
+deploy: off
diff --git a/vendor/github.com/pkg/errors/errors.go b/vendor/github.com/pkg/errors/errors.go
new file mode 100644
index 000000000..1963d86bf
--- /dev/null
+++ b/vendor/github.com/pkg/errors/errors.go
@@ -0,0 +1,282 @@
+// Package errors provides simple error handling primitives.
+//
+// The traditional error handling idiom in Go is roughly akin to
+//
+// if err != nil {
+// return err
+// }
+//
+// which when applied recursively up the call stack results in error reports
+// without context or debugging information. The errors package allows
+// programmers to add context to the failure path in their code in a way
+// that does not destroy the original value of the error.
+//
+// Adding context to an error
+//
+// The errors.Wrap function returns a new error that adds context to the
+// original error by recording a stack trace at the point Wrap is called,
+// together with the supplied message. For example
+//
+// _, err := ioutil.ReadAll(r)
+// if err != nil {
+// return errors.Wrap(err, "read failed")
+// }
+//
+// If additional control is required, the errors.WithStack and
+// errors.WithMessage functions destructure errors.Wrap into its component
+// operations: annotating an error with a stack trace and with a message,
+// respectively.
+//
+// Retrieving the cause of an error
+//
+// Using errors.Wrap constructs a stack of errors, adding context to the
+// preceding error. Depending on the nature of the error it may be necessary
+// to reverse the operation of errors.Wrap to retrieve the original error
+// for inspection. Any error value which implements this interface
+//
+// type causer interface {
+// Cause() error
+// }
+//
+// can be inspected by errors.Cause. errors.Cause will recursively retrieve
+// the topmost error that does not implement causer, which is assumed to be
+// the original cause. For example:
+//
+// switch err := errors.Cause(err).(type) {
+// case *MyError:
+// // handle specifically
+// default:
+// // unknown error
+// }
+//
+// Although the causer interface is not exported by this package, it is
+// considered a part of its stable public interface.
+//
+// Formatted printing of errors
+//
+// All error values returned from this package implement fmt.Formatter and can
+// be formatted by the fmt package. The following verbs are supported:
+//
+// %s print the error. If the error has a Cause it will be
+// printed recursively.
+// %v see %s
+// %+v extended format. Each Frame of the error's StackTrace will
+// be printed in detail.
+//
+// Retrieving the stack trace of an error or wrapper
+//
+// New, Errorf, Wrap, and Wrapf record a stack trace at the point they are
+// invoked. This information can be retrieved with the following interface:
+//
+// type stackTracer interface {
+// StackTrace() errors.StackTrace
+// }
+//
+// The returned errors.StackTrace type is defined as
+//
+// type StackTrace []Frame
+//
+// The Frame type represents a call site in the stack trace. Frame supports
+// the fmt.Formatter interface that can be used for printing information about
+// the stack trace of this error. For example:
+//
+// if err, ok := err.(stackTracer); ok {
+// for _, f := range err.StackTrace() {
+// fmt.Printf("%+s:%d", f)
+// }
+// }
+//
+// Although the stackTracer interface is not exported by this package, it is
+// considered a part of its stable public interface.
+//
+// See the documentation for Frame.Format for more details.
+package errors
+
+import (
+ "fmt"
+ "io"
+)
+
+// New returns an error with the supplied message.
+// New also records the stack trace at the point it was called.
+func New(message string) error {
+ return &fundamental{
+ msg: message,
+ stack: callers(),
+ }
+}
+
+// Errorf formats according to a format specifier and returns the string
+// as a value that satisfies error.
+// Errorf also records the stack trace at the point it was called.
+func Errorf(format string, args ...interface{}) error {
+ return &fundamental{
+ msg: fmt.Sprintf(format, args...),
+ stack: callers(),
+ }
+}
+
+// fundamental is an error that has a message and a stack, but no caller.
+type fundamental struct {
+ msg string
+ *stack
+}
+
+func (f *fundamental) Error() string { return f.msg }
+
+func (f *fundamental) Format(s fmt.State, verb rune) {
+ switch verb {
+ case 'v':
+ if s.Flag('+') {
+ io.WriteString(s, f.msg)
+ f.stack.Format(s, verb)
+ return
+ }
+ fallthrough
+ case 's':
+ io.WriteString(s, f.msg)
+ case 'q':
+ fmt.Fprintf(s, "%q", f.msg)
+ }
+}
+
+// WithStack annotates err with a stack trace at the point WithStack was called.
+// If err is nil, WithStack returns nil.
+func WithStack(err error) error {
+ if err == nil {
+ return nil
+ }
+ return &withStack{
+ err,
+ callers(),
+ }
+}
+
+type withStack struct {
+ error
+ *stack
+}
+
+func (w *withStack) Cause() error { return w.error }
+
+func (w *withStack) Format(s fmt.State, verb rune) {
+ switch verb {
+ case 'v':
+ if s.Flag('+') {
+ fmt.Fprintf(s, "%+v", w.Cause())
+ w.stack.Format(s, verb)
+ return
+ }
+ fallthrough
+ case 's':
+ io.WriteString(s, w.Error())
+ case 'q':
+ fmt.Fprintf(s, "%q", w.Error())
+ }
+}
+
+// Wrap returns an error annotating err with a stack trace
+// at the point Wrap is called, and the supplied message.
+// If err is nil, Wrap returns nil.
+func Wrap(err error, message string) error {
+ if err == nil {
+ return nil
+ }
+ err = &withMessage{
+ cause: err,
+ msg: message,
+ }
+ return &withStack{
+ err,
+ callers(),
+ }
+}
+
+// Wrapf returns an error annotating err with a stack trace
+// at the point Wrapf is called, and the format specifier.
+// If err is nil, Wrapf returns nil.
+func Wrapf(err error, format string, args ...interface{}) error {
+ if err == nil {
+ return nil
+ }
+ err = &withMessage{
+ cause: err,
+ msg: fmt.Sprintf(format, args...),
+ }
+ return &withStack{
+ err,
+ callers(),
+ }
+}
+
+// WithMessage annotates err with a new message.
+// If err is nil, WithMessage returns nil.
+func WithMessage(err error, message string) error {
+ if err == nil {
+ return nil
+ }
+ return &withMessage{
+ cause: err,
+ msg: message,
+ }
+}
+
+// WithMessagef annotates err with the format specifier.
+// If err is nil, WithMessagef returns nil.
+func WithMessagef(err error, format string, args ...interface{}) error {
+ if err == nil {
+ return nil
+ }
+ return &withMessage{
+ cause: err,
+ msg: fmt.Sprintf(format, args...),
+ }
+}
+
+type withMessage struct {
+ cause error
+ msg string
+}
+
+func (w *withMessage) Error() string { return w.msg + ": " + w.cause.Error() }
+func (w *withMessage) Cause() error { return w.cause }
+
+func (w *withMessage) Format(s fmt.State, verb rune) {
+ switch verb {
+ case 'v':
+ if s.Flag('+') {
+ fmt.Fprintf(s, "%+v\n", w.Cause())
+ io.WriteString(s, w.msg)
+ return
+ }
+ fallthrough
+ case 's', 'q':
+ io.WriteString(s, w.Error())
+ }
+}
+
+// Cause returns the underlying cause of the error, if possible.
+// An error value has a cause if it implements the following
+// interface:
+//
+// type causer interface {
+// Cause() error
+// }
+//
+// If the error does not implement Cause, the original error will
+// be returned. If the error is nil, nil will be returned without further
+// investigation.
+func Cause(err error) error {
+ type causer interface {
+ Cause() error
+ }
+
+ for err != nil {
+ cause, ok := err.(causer)
+ if !ok {
+ break
+ }
+ err = cause.Cause()
+ }
+ return err
+}
diff --git a/vendor/github.com/pkg/errors/stack.go b/vendor/github.com/pkg/errors/stack.go
new file mode 100644
index 000000000..2874a048c
--- /dev/null
+++ b/vendor/github.com/pkg/errors/stack.go
@@ -0,0 +1,147 @@
+package errors
+
+import (
+ "fmt"
+ "io"
+ "path"
+ "runtime"
+ "strings"
+)
+
+// Frame represents a program counter inside a stack frame.
+type Frame uintptr
+
+// pc returns the program counter for this frame;
+// multiple frames may have the same PC value.
+func (f Frame) pc() uintptr { return uintptr(f) - 1 }
+
+// file returns the full path to the file that contains the
+// function for this Frame's pc.
+func (f Frame) file() string {
+ fn := runtime.FuncForPC(f.pc())
+ if fn == nil {
+ return "unknown"
+ }
+ file, _ := fn.FileLine(f.pc())
+ return file
+}
+
+// line returns the line number of source code of the
+// function for this Frame's pc.
+func (f Frame) line() int {
+ fn := runtime.FuncForPC(f.pc())
+ if fn == nil {
+ return 0
+ }
+ _, line := fn.FileLine(f.pc())
+ return line
+}
+
+// Format formats the frame according to the fmt.Formatter interface.
+//
+// %s source file
+// %d source line
+// %n function name
+// %v equivalent to %s:%d
+//
+// Format accepts flags that alter the printing of some verbs, as follows:
+//
+// %+s function name and path of source file relative to the compile time
+// GOPATH separated by \n\t (<funcname>\n\t<path>)
+// %+v equivalent to %+s:%d
+func (f Frame) Format(s fmt.State, verb rune) {
+ switch verb {
+ case 's':
+ switch {
+ case s.Flag('+'):
+ pc := f.pc()
+ fn := runtime.FuncForPC(pc)
+ if fn == nil {
+ io.WriteString(s, "unknown")
+ } else {
+ file, _ := fn.FileLine(pc)
+ fmt.Fprintf(s, "%s\n\t%s", fn.Name(), file)
+ }
+ default:
+ io.WriteString(s, path.Base(f.file()))
+ }
+ case 'd':
+ fmt.Fprintf(s, "%d", f.line())
+ case 'n':
+ name := runtime.FuncForPC(f.pc()).Name()
+ io.WriteString(s, funcname(name))
+ case 'v':
+ f.Format(s, 's')
+ io.WriteString(s, ":")
+ f.Format(s, 'd')
+ }
+}
+
+// StackTrace is stack of Frames from innermost (newest) to outermost (oldest).
+type StackTrace []Frame
+
+// Format formats the stack of Frames according to the fmt.Formatter interface.
+//
+// %s lists source files for each Frame in the stack
+// %v lists the source file and line number for each Frame in the stack
+//
+// Format accepts flags that alter the printing of some verbs, as follows:
+//
+// %+v Prints filename, function, and line number for each Frame in the stack.
+func (st StackTrace) Format(s fmt.State, verb rune) {
+ switch verb {
+ case 'v':
+ switch {
+ case s.Flag('+'):
+ for _, f := range st {
+ fmt.Fprintf(s, "\n%+v", f)
+ }
+ case s.Flag('#'):
+ fmt.Fprintf(s, "%#v", []Frame(st))
+ default:
+ fmt.Fprintf(s, "%v", []Frame(st))
+ }
+ case 's':
+ fmt.Fprintf(s, "%s", []Frame(st))
+ }
+}
+
+// stack represents a stack of program counters.
+type stack []uintptr
+
+func (s *stack) Format(st fmt.State, verb rune) {
+ switch verb {
+ case 'v':
+ switch {
+ case st.Flag('+'):
+ for _, pc := range *s {
+ f := Frame(pc)
+ fmt.Fprintf(st, "\n%+v", f)
+ }
+ }
+ }
+}
+
+func (s *stack) StackTrace() StackTrace {
+ f := make([]Frame, len(*s))
+ for i := 0; i < len(f); i++ {
+ f[i] = Frame((*s)[i])
+ }
+ return f
+}
+
+func callers() *stack {
+ const depth = 32
+ var pcs [depth]uintptr
+ n := runtime.Callers(3, pcs[:])
+ var st stack = pcs[0:n]
+ return &st
+}
+
+// funcname removes the path prefix component of a function's name reported by func.Name().
+func funcname(name string) string {
+ i := strings.LastIndex(name, "/")
+ name = name[i+1:]
+ i = strings.Index(name, ".")
+ return name[i+1:]
+}
diff --git a/vendor/vendor.json b/vendor/vendor.json
index 3b9328a56..3bd4b829e 100644
--- a/vendor/vendor.json
+++ b/vendor/vendor.json
@@ -35,10 +35,12 @@
"versionExact": "v1.1.1"
},
{
- "checksumSHA1": "hURIsCBKqzNJaOVu3/76F6dfQJ0=",
+ "checksumSHA1": "hL8smC/vjdkuE1twM8TKpuTiOmw=",
"path": "github.com/getsentry/raven-go",
- "revision": "4fa2ac0d29f801e79a063c0da82d37b5ff2873b2",
- "revisionTime": "2017-01-17T02:28:26Z"
+ "revision": "3033899c76deb3fb6570d9c4074d00443aeab88f",
+ "revisionTime": "2018-10-23T13:08:49Z",
+ "version": "v0",
+ "versionExact": "v0.1.0"
},
{
"checksumSHA1": "ITzWX1LucDMHcZh509uUwc920KY=",
@@ -143,6 +145,14 @@
"revisionTime": "2016-04-24T11:30:07Z"
},
{
+ "checksumSHA1": "DTy0iJ2w5C+FDsN9EnzfhNmvS+o=",
+ "path": "github.com/pkg/errors",
+ "revision": "059132a15dd08d6704c67711dae0cf35ab991756",
+ "revisionTime": "2018-10-23T23:59:46Z",
+ "version": "master",
+ "versionExact": "master"
+ },
+ {
"checksumSHA1": "LuFv4/jlrmFNnDb/5SCSEPAM9vU=",
"path": "github.com/pmezard/go-difflib/difflib",
"revision": "792786c7400a136282c1664665ae0a8db921c6c2",