4 ms·
I honestly don't understand where you're coming from. Rolling your own error library is trivial. We have a great one at work that works great, prints stack tra
by jknoepfler 7y ago
I honestly don't understand where you're coming from.
Rolling your own error library is trivial. We have a great one at work that works great, prints stack traces, interops with normal error handlers, and does a lot of custom work for translating errors into external customer-visible messages and internal developer messages. We use it at every layer of a 50-60 grpc microservice ecosystem without much headache.
Catching deferred errors is trivial, not sure what you mean there:
defer func () {
err := f.Close()
...
}()
Printing stack traces is like 4 lines, I was able to implement ours in 60 minutes of doc skimming. Now it'd be 5 minutes.
I don't understand your last two sentences. It doesn't reflect anything I've run into in the real world, I don't think.
I have a few gripes about golang, but the minimalist error interface is not one of them.
- mav3rick 7y agoEveryone should not have to have their own error library for basic functionality or custom foo to print stacktraces.
- jknoepfler 7y agoThe idea of carrying around bloated errors everywhere is absurd to me, especially in a microservice ecosystem where that all has to cross the wire, potentially multiple times.
- mav3rick 7y agoYou just return codes between IPC or inter-service communication. No one is asking you to serialize error objects and send them.
- TheDong 7y agoRegarding "Auto promoted to not-nil interfaces", here's what it looks like: https://play.golang.org/p/7Gs76Nt-h4b https://play.golang.org/p/7Gs76Nt-h4b That issue is one of the reasons everything has to return 'error', not your own struct that might be more convenient to work with. I've run into it in the wild in dozens of codebases, so it's definitely a real issue. Without generics and covariance, it's an uphill battle to create usable monadic error handling in Go. If all you've used before is C which has int returns and globals for error handling, I can see how go's error handling looks nice, but compared to most languages invented in the last 20 years, it feels far worse.
- Vendan 7y agoOne way to work around that is to use interfaces (https://play.golang.org/p/aAEAi8GvDkv https://play.golang.org/p/aAEAi8GvDkv), but either way, you are "shadowing" the type, and can no longer use the .TraceID in the second function cause it's just a plain error at that point.
- coldtea 7y ago>I honestly don't understand where you're coming from. Perhaps they're coming from experience with better languages? >Rolling your own error library is trivial. And having to do so is a huge smell, if I ever smelt one...
- barrkel 7y agoHow do you convince every other library that you might sandwich on your call stack to use your error library so your error data gets passed through correctly?
- tptacek 7y agoWell, at this point, don't you just wrap the error? Isn't that the point of this post?
- barrkel 7y agoAnd stack trace in the middle?
- _ph_ 7y agoThe other library doesn't have to use your error library, it just needs to preserve your error when passing through. To make this a common practise, this proposal was made.
- apta 7y ago> We have a great one at work that works great, prints stack traces Sounds like the C and C++ situation where each company and large project rolls out their own string implementation.
- pstuart 7y agoThat was their itch to scratch. Please tell me about your language which has every single feature you need built into the standard library?
- pjmlp 7y agoPython, Java and .NET, pretty much. There are still stuff missing, but not basic low level stuff that everyone uses daily.
- littlestymaar 7y agoIt can be in the std, or it can be available as a package in your language package manager. But Go doesn't shine in dependency management either. Minimalist standard library doesn't go well with their philosophy around dependency (“a little copying is better than a little dependency”). That's why the made so much stuff in std.
- weberc2 7y agoPretty sure modules addresses the dependency management concerns, no?
- JustARandomGuy 7y ago>Rolling your own error library is trivial. And right there is where you’re going to lose most people. If it’s is trivial, why isn’t in the standard library? If everyone needs to do it, why not standardize? I love Go, but i have to agree with grandparent poster.
- cpuguy83 7y agoYou can't standardize until people agree. The trivial part isn't the code it's what is acceptable to everyone. If people don't agree then it by definition does not belong in the stdlib.
- TheDong 7y agoPeople disagreeing is even more the reason to standardize for things that matter to the broad ecosystem. For example, no one likes gofmt (tabs, eww), but everyone likes code across packages looking the same. And so we use it.
- cpuguy83 7y agoand gofmt existed before go really had a large community. It's also a very different problem because you can change formatting decisions from one version to another (and they do!), but API's are difficult to change.
- Vendan 7y agoSpeak for yourself, Go is a bastion of formatting sanity for me cause they chose (correctly) to use tabs. Tabs for indentation are the obvious choice to improve code readability and accessibility for people that want different indent sizes. I don't need it (usually), but I've met people that prefer everything from 2, 4 or 8 spaces, and have heard of people wanting everything from 1 to 8. It also handles far more sanely then spaces for people using proportional fonts instead of monospace, another common readability/accessibility tweak.
- cpuguy83 7y ago*the hard part isn't the code I guess I finished that sentence in a different way than I started it.