How to get the stack trace pointing to actual error reason

serejja

Let's say I have some code like this:

value, err := some3rdpartylib.DoSomething()
if err != nil {
    panic(err)
}

In case err != nil I will get something like this:

panic: some error explanation here

goroutine 1 [running]:
main.main()
    /tmp/blabla/main.go:6 +0x80

This stack trace is completely legit but sometimes these error messages may not clarify what happened and so I'd like to dig deeper into the source code of the 3rd party library to investigate what exactly causes this error to be returned. However when my code panics like this, there is no way to get the actual place that returned this error.

A little bit more clarification: as I'm coming from JVM world where exceptions are thrown I can completely trace what exactly line of code thrown the exception and thus can easily find the place and see what gone wrong. Go stack trace ends exactly where my code panics and thus not too useful in my case.

I've created a playground here and ideally I'd like to be able to trace the error to the place it was actually returned from, not panic. (e.g. to line 17, return "", errors.New("some error explanation here"))

Is this even possible?

Kokos

Shortly: this is not possible. Since errors are values, they are not treated in any special way. Due to this, when function (normally) returns, stack is no more available (ie. another function call may overwrite memory used by returning-error function' stack).

There is a tool called trace which was introduced with go1.5, but for now, there is no comprehensive tutorial available neither any of those I found says that this kind of feature will be included.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to get error and stack trace as JSON in symfony2?

From Dev

How to get *native* stack-trace on error for Java native agent?

From Dev

How to get error and stack trace as JSON in symfony2?

From Dev

How to get a stack trace in Rails?

From Dev

Lua: How to call error without stack trace

From Dev

How to get the full stack trace for async execution

From Dev

How to get function stack trace for any function?

From Dev

Request repr() unavailable in Django 500 error email: how do I debug how to get the full stack trace?

From Dev

Request repr() unavailable in Django 500 error email: how do I debug how to get the full stack trace?

From Dev

Get actual path symlink is pointing to

From Dev

How can I get the "Source Error" from a stack trace like Asp.Net does?

From Dev

Get complete stack trace for one-line fatal php error

From Dev

Get complete stack trace for one-line fatal php error

From Dev

How can I get the disk IO trace with actual input values?

From Dev

how to trace this stack and pointer

From Dev

How to not show stack trace in Gulp task error callback?

From Dev

nginx + python app -- how to enable error logging/stack trace

From Dev

How to obtain a full stack trace when test fails with an error?

From Dev

How do you get the JavaScript stack trace from Nashorn?

From Java

How can I get the current stack trace in Java?

From Dev

Java - how to get the stack trace from before a Runnable?

From Dev

How to get a stack trace for "Invalid chrome URI" exceptions?

From Dev

How to get stack trace string without raising exception in python?

From Dev

How to get errors stack trace in Chrome extension content script?

From Dev

java - How can I get a future's stack trace on TimeoutException

From Dev

How to get stack trace string without raising exception in python?

From Dev

How to get errors stack trace in Chrome extension content script?

From Dev

How to get package data [jar file name] from stack trace?

From Dev

Error Details without Stack Trace

Related Related

  1. 1

    How to get error and stack trace as JSON in symfony2?

  2. 2

    How to get *native* stack-trace on error for Java native agent?

  3. 3

    How to get error and stack trace as JSON in symfony2?

  4. 4

    How to get a stack trace in Rails?

  5. 5

    Lua: How to call error without stack trace

  6. 6

    How to get the full stack trace for async execution

  7. 7

    How to get function stack trace for any function?

  8. 8

    Request repr() unavailable in Django 500 error email: how do I debug how to get the full stack trace?

  9. 9

    Request repr() unavailable in Django 500 error email: how do I debug how to get the full stack trace?

  10. 10

    Get actual path symlink is pointing to

  11. 11

    How can I get the "Source Error" from a stack trace like Asp.Net does?

  12. 12

    Get complete stack trace for one-line fatal php error

  13. 13

    Get complete stack trace for one-line fatal php error

  14. 14

    How can I get the disk IO trace with actual input values?

  15. 15

    how to trace this stack and pointer

  16. 16

    How to not show stack trace in Gulp task error callback?

  17. 17

    nginx + python app -- how to enable error logging/stack trace

  18. 18

    How to obtain a full stack trace when test fails with an error?

  19. 19

    How do you get the JavaScript stack trace from Nashorn?

  20. 20

    How can I get the current stack trace in Java?

  21. 21

    Java - how to get the stack trace from before a Runnable?

  22. 22

    How to get a stack trace for "Invalid chrome URI" exceptions?

  23. 23

    How to get stack trace string without raising exception in python?

  24. 24

    How to get errors stack trace in Chrome extension content script?

  25. 25

    java - How can I get a future's stack trace on TimeoutException

  26. 26

    How to get stack trace string without raising exception in python?

  27. 27

    How to get errors stack trace in Chrome extension content script?

  28. 28

    How to get package data [jar file name] from stack trace?

  29. 29

    Error Details without Stack Trace

HotTag

Archive