Skip to content
This repository was archived by the owner on Dec 1, 2021. It is now read-only.
This repository was archived by the owner on Dec 1, 2021. It is now read-only.

Revert change to errors.Frame's type #188

Closed
@davecheney

Description

@davecheney
Member

In #183 the definition of errors.Frame was altered to type Frame runtime.Frame. This was necessary because of the changes to mid stack inlining in Go 1.12 and the deprecation of runtime.FuncForPC.

https://go-review.googlesource.com/c/go/+/156364 suggests that it may be possible to continue to use runtime.FuncForPC. If this CL lands #183 should be mostly reverted for the 1.0 release.

A future v2 release would probably drop the use of runtime.FuncForPC and redeclare errors.Frame as an opaque struct.

Activity

added this to the 0.9 milestone on Jan 6, 2019
arcana261

arcana261 commented on Jan 6, 2019

@arcana261

I agree.. Since we can obtain runtime.Frame from PC's we could have just let good ol' Frame stay there. But I don't know whether it's too late to revert this breaking change or not. Other libraries might have adopted this change :(

davecheney

davecheney commented on Jan 6, 2019

@davecheney
MemberAuthor

.. Since we can obtain runtime.Frame

How would you do that?

As to breaking change on master, I tagged v0.8.1 before I made this change.

arcana261

arcana261 commented on Jan 6, 2019

@arcana261

using runtime.CallersFrames? maybe?

Thank you for tagging.. much appreciated ^_^

arcana261

arcana261 commented on Jan 6, 2019

@arcana261

we could alter implementation of format like this:

// format allows stack trace printing calls to be made with a bytes.Buffer.
func (ptrFrame Frame) format(w io.Writer, s fmt.State, verb rune) {
	frames := runtime.CallersFrames([]uintptr{uintptr(ptrFrame)})
	if frames == nil {
		return
	}
	f, _ := frames.Next()

....
davecheney

davecheney commented on Jan 6, 2019

@davecheney
MemberAuthor
arcana261

arcana261 commented on Jan 6, 2019

@arcana261

I understand. I was merely pointing out that we could obtain an instance of runtime.Frame this way instead of #183 . And we could use runtime.Frame.Function, runtime.Frame.Line.. etc. And I've confirmed that we can accurately convert a single PC to runtime.Frame.

Complete listing is as follows:
Basically it's #183 without changing type of errors.Frame. Instead a we convert a single PC to runtime.Frame and the rest is still #183

// format allows stack trace printing calls to be made with a bytes.Buffer.
func (ptrFrame Frame) format(w io.Writer, s fmt.State, verb rune) {
	frames := runtime.CallersFrames([]uintptr{uintptr(ptrFrame)})
	if frames == nil {
		return
	}
	f, _ := frames.Next()

	switch verb {
	case 's':
		switch {
		case s.Flag('+'):
			fn := runtime.Frame(f).Func
			if fn == nil {
				io.WriteString(w, "unknown")
			} else {
				file := runtime.Frame(f).File
				io.WriteString(w, fn.Name())
				io.WriteString(w, "\n\t")
				io.WriteString(w, file)
			}
		default:
			file := runtime.Frame(f).File
			if file == "" {
				file = "unknown"
			}
			io.WriteString(w, path.Base(file))
		}
	case 'd':
		io.WriteString(w, strconv.Itoa(runtime.Frame(f).Line))
	case 'n':
		name := runtime.Frame(f).Function
		io.WriteString(s, funcname(name))
	case 'v':
		ptrFrame.format(w, s, 's')
		io.WriteString(w, ":")
		ptrFrame.format(w, s, 'd')
	}
}
davecheney

davecheney commented on Jan 6, 2019

@davecheney
MemberAuthor
uberbo

uberbo commented on Jan 7, 2019

@uberbo

Is there any reason for using runtime.Frame(f).Func.Name() instead of runtime.Frame(f).Function?

dcu

dcu commented on Jan 8, 2019

@dcu

aws/aws-xray-sdk-go#77 is related to this

davecheney

davecheney commented on Jan 8, 2019

@davecheney
MemberAuthor
davecheney

davecheney commented on Jan 9, 2019

@davecheney
MemberAuthor

Closed in #193

4 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @davecheney@dcu@arcana261@uberbo

        Issue actions

          Revert change to errors.Frame's type · Issue #188 · pkg/errors