Feature request and horrible hack: break on next returned error

21 views
Skip to first unread message

Tom Payne

unread,
Oct 16, 2019, 10:21:23 PM10/16/19
to delve-dev
Hi,

tl;dr would it be possible to break as soon as any function returns a non-nil error?

Apologies if this has already been requested. I did several searches but was unable to find an equivalent request.

More detail:

Go treats errors as first-class values. When a function returns an error, that error tends to bubble up the stack. The original source of the error is often lost and hard to track down. This is improving with Go 1.13's wrapped errors, but still requires the programmer to explicitly wrap those errors.

It would be really nice if there was a "continue until any function returns a non-nil error" command. This would require instrumenting any return statement that returns an error value, stopping execution at that point, and consequently reveal the underlying source of a bubbled-up error. Repeating the command would follow the bubbled error up the stack.

Many thanks for Delve - it's been invaluable for me.

Tom

Tom Payne

unread,
Oct 16, 2019, 10:29:18 PM10/16/19
to delve-dev
For what it's worth, implementing this would require effectively replacing every

    return err

with

    return breakOnError(err)

where breakOnError is:

func breakOnError(err error) error {
if err != nil {
runtime.Breakpoint()
}
return err

Alessandro Arzilli

unread,
Oct 17, 2019, 8:07:17 AM10/17/19
to Tom Payne, delve-dev
You can do this, sort of, with some starlark scripting plus the API call
FindReturnLocations. I don't think it's feasible to do this for all
functions in the program, I think it would slow down execution too much and
generate too many false positives.
> --
> You received this message because you are subscribed to the Google Groups "delve-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to delve-dev+...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/delve-dev/4b5961b8-8617-443a-a9c6-ecaab6e1d122%40googlegroups.com.

Tom Payne

unread,
Oct 20, 2019, 8:44:27 PM10/20/19
to Alessandro Arzilli, delve-dev
Thank you very much for the response - I'll investigate further.
Reply all
Reply to author
Forward
0 new messages