How to get the stack trace pointing to actual error reason

I think that there is an easier way to achieve this. You can try wrapping errors using the golang “default” third party library error package:

You need to define the interface to be implemented by your error :

type stackTracer interface {
    StackTrace() errors.StackTrace
}

Then use it when wrapping/processing an error :

err, ok := errors.(stackTracer) // ok is false if errors doesn't implement stackTracer

stack := err.StackTrace()
fmt.Println(stack) // here you'll have your stack trace

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)