A good error message might look like this:
Could not travel to Alpha Centauri:
warp drive initialization failed:
power coupling 397 is offline:
temperature out of range (temp = 150°C)
A bad stack trace might look like this: DeviceClient::Connect()
std::promise::something
<anonymous function>
DeviceSet::PowerOnAllDevices()
<anonymous function>
std::etcetera
std::etcetera<some_big_thing, more_params, allocator=std::allocator>
TravelCommand::Engage()
VoiceCommand::RunCommand()
Error: temperature out of range (temp = 150°C)
Stack traces are useful, but they're a poor substitute for good error messages. There's just too much context missing from raw stack traces (which file, which URL, which device) and too much noise (anonymous functions, higher-order functions, etc.) That, and a stack trace often requires reading the source code to interpret properly. That might not be possible or it might be outside the skill set of the person interpreting the error.Exceptions optimize for the case where the exception bubbles straight up to some handler, but I'd rather not have my errors work that way. It's incredibly common for it to make no sense to bubble an error up without some kind of annotation or additional context.
return errors.New("")
You have control over whether the error messages are good or bad, you just have to insert the right annotations where the critical pieces of context are known.Stack traces are not like this, you can't really control whether they are good or bad, at least not well. If you want to make your stack traces more informative what do you do? You can't really change them, they just reflect your call graph.
Golang optimizes for the case where you get good error messages. Exceptions optimize for the case where you don't care about adding context to the error and just want to bubble it upwards. On the balance of things, I prefer Golang's approach because most of the time, I don't want to see the stack trace.
[Edit: this was a reply to a comment you seem to have rewritten (I think for the worse) but I think the response still mostly works]
errors are "failure as data" (hence, message), and you get to write the flow (including handling and annotating the call stack)
vs
exceptions are "failure as flow" (hence, stack trace), and you get to write the data (including logging)
May very well be paraphrasing a well known maxim about closures and objects as errors are a poor man's exceptions and exceptions are a poor man's errors.