Exemple #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
}
Exemple #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
}
Exemple #3
0
// 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
}
Exemple #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 ""
}