Sha256: c54035b2bee1ecd22d5d0afbd7c3765a6feaa4177e7bb08a60fe0073c53b06f2

Contents?: true

Size: 1.49 KB

Versions: 16

Compression:

Stored size: 1.49 KB

Contents

// Copyright 2018 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package xerrors

import (
	"runtime"
)

// A Frame contains part of a call stack.
type Frame struct {
	// Make room for three PCs: the one we were asked for, what it called,
	// and possibly a PC for skipPleaseUseCallersFrames. See:
	// https://go.googlesource.com/go/+/032678e0fb/src/runtime/extern.go#169
	frames [3]uintptr
}

// Caller returns a Frame that describes a frame on the caller's stack.
// The argument skip is the number of frames to skip over.
// Caller(0) returns the frame for the caller of Caller.
func Caller(skip int) Frame {
	var s Frame
	runtime.Callers(skip+1, s.frames[:])
	return s
}

// location reports the file, line, and function of a frame.
//
// The returned function may be "" even if file and line are not.
func (f Frame) location() (function, file string, line int) {
	frames := runtime.CallersFrames(f.frames[:])
	if _, ok := frames.Next(); !ok {
		return "", "", 0
	}
	fr, ok := frames.Next()
	if !ok {
		return "", "", 0
	}
	return fr.Function, fr.File, fr.Line
}

// Format prints the stack as error detail.
// It should be called from an error's Format implementation
// after printing any other error detail.
func (f Frame) Format(p Printer) {
	if p.Detail() {
		function, file, line := f.location()
		if function != "" {
			p.Printf("%s\n    ", function)
		}
		if file != "" {
			p.Printf("%s:%d\n", file, line)
		}
	}
}

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
ruby_snowflake_client-1.3.7 ext/vendor/golang.org/x/xerrors/frame.go
ruby_snowflake_client-1.3.6 ext/vendor/golang.org/x/xerrors/frame.go
ruby_snowflake_client-1.3.5 ext/vendor/golang.org/x/xerrors/frame.go
ruby_snowflake_client-1.3.4 ext/vendor/golang.org/x/xerrors/frame.go
ruby_snowflake_client-1.3.4.pre.debug ext/vendor/golang.org/x/xerrors/frame.go
ruby_snowflake_client-1.3.3.pre.debug ext/vendor/golang.org/x/xerrors/frame.go
ruby_snowflake_client-1.3.2 ext/vendor/golang.org/x/xerrors/frame.go
ruby_snowflake_client-1.3.1 ext/vendor/golang.org/x/xerrors/frame.go
ruby_snowflake_client-1.3.0 ext/vendor/golang.org/x/xerrors/frame.go
ruby_snowflake_client-1.2.1 ext/vendor/golang.org/x/xerrors/frame.go
ruby_snowflake_client-1.2.0 ext/vendor/golang.org/x/xerrors/frame.go
ruby_snowflake_client-1.1.1 ext/vendor/golang.org/x/xerrors/frame.go
ruby_snowflake_client-1.1.0 ext/vendor/golang.org/x/xerrors/frame.go
ruby_snowflake_client-1.0.2 ext/vendor/golang.org/x/xerrors/frame.go
ruby_snowflake_client-1.0.1 ext/vendor/golang.org/x/xerrors/frame.go
ruby_snowflake_client-1.0.0 ext/vendor/golang.org/x/xerrors/frame.go