News for hackers. Stuff that matters.
Re:Upcoming Features in Go 1.18 by morelisp on Tuesday November 09, 2021 @12:21PM (#29164452)
Please no allocations hidden in the short syntax. I use `errors.WithMessage` / `fmt.Errorf` with `%w` often within my application's main execution flow, but I don't need a stack trace attached to every missing file, parse failure, or connection reset.
Re:Upcoming Features in Go 1.18 by silisili on Tuesday November 09, 2021 @12:34PM (#29164625)
Apologies, to be more precise, my team wraps every error in a filename/line number pair, not an entire stacktrace.
Re:Upcoming Features in Go 1.18 by morelisp on Tuesday November 09, 2021 @01:00PM (#29165008)
What is the (moral or performance) difference between wrapping every error you return anywhere with a filename/lineno pair, and a stack trace? If anything, the stacktrace proper probably only needs to allocate once, at the lowest level.
Re:Upcoming Features in Go 1.18 by silisili on Tuesday November 09, 2021 @01:14PM (#29165184)
The specifics of it are deep enough in runtime that I've never actually looked, but it's designed as a chain to return a specific caller - it looks like -

    _, file, line, _ := runtime.Caller(2)
    locTxt := fmt.Sprintf(" (at %s:%d)", filepath.Base(file), line)
I think if the above on errors became a performance concern, I'd heavily rethink what I considered an error. But, it is also possible the systems we've designed are miles apart in function and philosophy.
Re:Upcoming Features in Go 1.18 by morelisp on Tuesday November 09, 2021 @01:21PM (#29165291)
Yeah, this is fine for like "unable to contact database server" or "kafka producer timeout" where you're gonna terminate a large portion (or all) of the application at a much higher, removed level. "Lifecycle" stuff.

But if you make the short syntax do something like this, it's gonna get used for hundreds of library's equivalents of `Atoi` or `ParseQuery`. I don't need line annotations on my `http.ResponseWriter#Write` timeouts, they're slow enough already.

(And if you are going to do it - really, just attach the whole stack trace then and there, it will probably be faster.)

Re:Upcoming Features in Go 1.18 by mariusor on Wednesday November 10, 2021 @03:00AM (#29172213)
I do this based on build tags for dev vs. production environments. In dev I attach the stacktrace to my errors, in prod I do not.