Merge pull request #17 from gravitational/alexander/leak

vendor things
This commit is contained in:
Alexander Klizhentas 2015-08-19 15:48:11 -07:00
commit 1a0af167e5
5 changed files with 90 additions and 1 deletions

4
Godeps/Godeps.json generated
View file

@ -68,6 +68,10 @@
"ImportPath": "github.com/gravitational/session",
"Rev": "dbae1e3eb55898f793640ff091929c6893fba69c"
},
{
"ImportPath": "github.com/gravitational/trace",
"Rev": "a2e1dddd4f3fa799922c2aa2ef65d783355839fc"
},
{
"ImportPath": "github.com/julienschmidt/httprouter",
"Rev": "b428fda53bb0a764fea9c76c9413512eda291dec"

View file

@ -0,0 +1,24 @@
# Compiled Object files, Static and Dynamic libs (Shared Objects)
*.o
*.a
*.so
# Folders
_obj
_test
# Architecture specific extensions/prefixes
*.[568vq]
[568vq].out
*.cgo1.go
*.cgo2.c
_cgo_defun.c
_cgo_gotypes.go
_cgo_export.*
_testmain.go
*.exe
*.test
*.prof

View file

@ -0,0 +1,2 @@
# trace
Package for error handling and error reporting

View file

@ -0,0 +1,59 @@
package trace
import (
"fmt"
"path/filepath"
"runtime"
)
// Wrap takes the original error and wraps it into the Trace struct
// memorizing the context of the error.
func Wrap(err error, args ...interface{}) error {
t := newTrace(runtime.Caller(1))
t.error = err
if len(args) != 0 {
t.Message = fmt.Sprintf(fmt.Sprintf("%v", args[0]), args[1:]...)
}
return t
}
// Errorf is similar to fmt.Errorf except that it captures
// more information about the origin of error, such as
// callee, line number and function that simplifies debugging
func Errorf(format string, args ...interface{}) error {
t := newTrace(runtime.Caller(1))
t.error = fmt.Errorf(format, args...)
return t
}
func newTrace(pc uintptr, filePath string, line int, ok bool) *TraceErr {
if !ok {
return &TraceErr{
File: "unknown_file",
Path: "unknown_path",
Func: "unknown_func",
Line: 0,
}
}
return &TraceErr{
File: filepath.Base(filePath),
Path: filePath,
Func: runtime.FuncForPC(pc).Name(),
Line: line,
}
}
// TraceErr contains error message and some additional
// information about the error origin
type TraceErr struct {
error
Message string
File string
Path string
Func string
Line int
}
func (e *TraceErr) Error() string {
return fmt.Sprintf("[%v:%v] %v %v", e.File, e.Line, e.Message, e.error)
}

View file

@ -6,8 +6,8 @@ import (
"os"
"path/filepath"
"github.com/gravitational/teleport/Godeps/_workspace/src/github.com/gravitational/trace"
"github.com/gravitational/teleport/backend"
"github.com/gravitational/trace"
)
// cfg represents JSON config for bolt backlend