Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AU-217] Make NCError implement StackTracer interface from aws-xray-sdk-go #6

Merged
merged 2 commits into from
Apr 1, 2022

Conversation

okonos
Copy link
Contributor

@okonos okonos commented Mar 30, 2022

Some anonymous interface actually, but current title seems more descriptive in the commit message limits.

errors/error.go Outdated Show resolved Hide resolved
frame := frame(st[1])
fileName, funcName, line = frame.getContext()
return
}

func callers() *stack {
func callers() []uintptr {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function (and probably a few others) is copied directly from the pkg/errors: https://github.com/pkg/errors/blob/master/stack.go#L163
The x-ray SDK supports both the generic []uintptr as well as the pkg/errors stacktrace format directly, so it seems strange that we need to change the code from pkg/errors to support the x-ray SDK. Any thoughts on this? 🤔

Copy link
Contributor Author

@okonos okonos Mar 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unaware of this having been copied, I've just removed it considering it was redundant (a custom type without any methods declared seemed so).

I reworked the solution to implement the pkg/errors "StackTrace interface" instead, since this package depends on it anyway. We could possibly update the pkg/errors to the latest version or to one matching that of aws-xray-sdk-go to avoid possible issues.

@@ -71,6 +80,16 @@ func GetRuntimeContext() (fileName, funcName string, line int) {
return
}

type stack []uintptr

func (s *stack) StackTrace() errors.StackTrace {
Copy link
Contributor Author

@okonos okonos Mar 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somewhat off-topic, but I wonder what's the point of declaring exported method on unexported type (I copied it over from pkg/errors)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fact that the type itself is not exported doesn't change the fact that the method can be called on that type. Unexported type just means you can not use the name of that type, but if you have a variable of that type you still can doe whatever is exported on that type. Also := operator works as well for unexported types (e.g. x := ConstructorOfUnexportedType) since it can bypass the need for actually using the name of the type (var x unexportedType would be illegal).

@@ -73,6 +75,8 @@ type NCError struct {
// Contains stack trace from the initial place when the error
// was raised.
Stack []string
// Raw stack trace in the form of program counters, as returned by the runtime.Callers
RawStack *stack
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be embedded instead? Dunno if it would work with the type being unexported 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what would not work here, but if there is no clear reason for embedding then I'd leave it as it is

Copy link
Contributor Author

@okonos okonos Mar 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rationale would be no need for the StackTrace method (re)definition. Currently it's more clear, though, I guess

}
return f
}

func callers() *stack {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't see the point of it returning a pointer and neither does the author

@okonos okonos merged commit 07de7a9 into master Apr 1, 2022
@okonos okonos deleted the au-217-implement-stack-tracer-interface branch April 1, 2022 14:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants