Exemplo n.º 1
0
// Location returns zero values if e has no stacktrace
func Location(e error) (file string, line int) {
	s := Stack(e)
	if len(s) > 0 {
		sf := goerr.NewStackFrame(s[0])
		return sf.File, sf.LineNumber
	}
	return "", 0
}
Exemplo n.º 2
0
func convertStack(stack []uintptr) []errors.StackFrame {
	frames := make([]errors.StackFrame, len(stack))
	for i, pc := range stack {
		// TODO: Handle panics correctly, as described in the
		// docs for runtime.Callers().
		frames[i] = errors.NewStackFrame(pc)
	}
	return frames
}
Exemplo n.º 3
0
Arquivo: trace.go Projeto: snikch/api
// StackFrames returns an array of errors.StackFrames containing information
// about the stack.
func (err *StackTraceError) StackFrames() []errors.StackFrame {
	if err.frames == nil {
		err.frames = make([]errors.StackFrame, len(err.stack))
		for i, pc := range err.stack {
			err.frames[i] = errors.NewStackFrame(pc)
		}
	}
	return err.frames
}
Exemplo n.º 4
0
// Stacktrace returns the error's stacktrace as a string formatted
// the same way as golangs runtime package.
// If e has no stacktrace, returns an empty string.
func Stacktrace(e error) string {
	s := Stack(e)
	if len(s) > 0 {
		buf := bytes.Buffer{}
		for _, fp := range s {
			sf := goerr.NewStackFrame(fp)
			buf.WriteString(sf.String())
		}
		return buf.String()
	}
	return ""
}