Hacker GitHub

← All repos

pkg/errors

View on GitHub ↗ ★ 8,257 Go

Simple error handling primitives

56 mentions on Hacker News by 49 people: 1 story, 55 comments · first 2016-05-02 · latest 2025-06-03

Mentions per year 56 mentions · busiest year 2019 (13)
20082026
  1. It's possible, stdlib just doesn't do it https://pkg.go.dev/github.com/pkg/errors
  2. It was likely using the previous default error lib github.com/pkg/errors
    comment by pstuart · 2025-06-01 · in Structured Errors in Go (2022)
  3. Go errors in standard library does not support stack traces. errors.Wrap() only exists in github.com/pkg/errors package
  4. https://github.com/pkg/errors provides stack traces support. This unfortunately did not get included in the Go1.13 release when error wrapping was introduced.
  5. …to debug the problem, regardless of what side the problem happens on. (At work we use a hacked up copy of github.com/pkg/errors, which grabs the entire stack trace at each of the errors.Wrap/errors.New call sites. This results in an…
    comment by jrockway · 2024-06-26 · in Three ways to think about Go channels
  6. …There is no errors.Wrap function. I was referring to this errors.Wrap function: https://pkg.go.dev/github.com/pkg/errors#Wrap I'm not a Go expert, is this function deprecated/removed? RE: errors are strings I probably didn't explain it too…
    comment by tubthumper8 · 2024-01-06 · in Go: What we got right, what we got wrong
  7. …to write your own Errorf() wrapper or some sort of WithStack() that stores runtime/debug.Stack() output. github.com/pkg/errors offers more flexibility in formatting though.
  8. …superseded by fmt.Errorf() with the %w directive. Go 1.20 also introduced errors.Join() and multi-%w which github.com/pkg/errors lack, so using for green field projects is very ill-advised.
  9. Can you explain why we should this over https://github.com/pkg/errors ?
  10. I hated it but I’ve grown into it, specially with the latest improvements and the https://pkg.go.dev/github.com/pkg/errors package. It’s still not as good as having Either/Try monads available to avoid the mess of “if err != nil” madness…
    comment by mlinhares · 2023-10-20 · in Banging errors in Go
  11. …part of the language proposal to make errors wrappable in Go’s stdlib included a stack trace. And indeed github.com/pkg/errors includes that. But it never made it into the stdlib implementation
    comment by linux2647 · 2023-08-06 · in Error Handling in Zig
  12. github.com/pkg/errors is dead — it’s been archived for a long time, and doesn’t incorporate go 1.20’s multi-error wrapping. Better switch to fmt.Errorf in new projects going forward.
    comment by oefrha · 2023-02-11 · in Gofumpt: A stricter gofmt
  13. …standard package or folded into the standard library IMHO, but Rust could do the same. [1]: https://github.com/pkg/errors
    comment by unscaled · 2022-03-31 · in Generics can make your Go code slower
  14. …not really possible to do this because the language doesn't provide such macros (i.e. the old third-party github.com/pkg/errors wanted you to implement 'Cause', but couldn't provide sugar like 'this-error' does for it because go is simply…
    comment by TheDong · 2022-03-30 · in Generics can make your Go code slower
  15. …to add to the error package but it didn't happen. You can use third party errors packages like https://github.com/pkg/errors which wrap errors with stack traces.
    comment by pkaye · 2021-12-14 · in Go Replaces Interface{} with 'Any'
  16. …of issues here which I think my fork addresses/fixes: Message formatting `WithMessage` vs. `Wrap`: https://github.com/pkg/errors/pull/114 Do not re-add stack trace if one is already there: https://github.com/pkg/errors/pull/122 Be explicit…
  17. …I haven't come to appreciate the decisions they've made that seemed controversial at the time. [0] https://github.com/pkg/errors
    comment by chrsig · 2021-10-17 · in Go: Don't Change the Libraries in 1.18
  18. …has been superseded by the native functionality in Go. [1]: https://go.dev/blog/go1.13-errors [2]: https://github.com/pkg/errors
    comment by unscaled · 2021-10-04 · in Things Go needs more than generics
  19. …generated as possible I've been doing something similar for a while, using `errors.WithStack` from https://github.com/pkg/errors The error can then be logged with https://github.com/rs/zerolog like this…
    comment by mozey · 2021-08-24 · in Error stack traces in Go with x/xerror
  20. At $DAYJOB we had a Go dependency on a package (maybe pkg/sftp?) that used github.com/pkg/errors to capture a stack trace with the error. These errors were ultimately used in a loop for flow control (maybe testing a lot of files/servers?)…
    comment by mappu · 2021-08-24 · in Error stack traces in Go with x/xerror
  21. github.com/pkg/errors also is a amazing option
    comment by durbatuluk · 2021-08-24 · in Error stack traces in Go with x/xerror
  22. …frames that handles the stack generation) in a deferred recover, ie https://play.golang.org/p/XvZteY6Y6fh github.com/pkg/errors is a simple way to dump expensive stacktraces into each new/wrapped error. Or you can just panic and recover in…
    comment by hcles · 2021-01-06 · in Learn Go in five minutes
  23. …like "Failed to initialize Foo: EOF". You can improve on this a little by using something like https://github.com/pkg/errors , which gives your errors a stack trace by default. But now your errors are hideous and unlikely to be fixable by…
    comment by nemo1618 · 2020-11-30 · in Error Handling Is Hard
  24. …experience with GoLand is that it manages to add back the right imports (notably with things like errors vs github.com/pkg/errors vs github.com/cockroachdb/errors, where they all share a package name and ~interface) but that might just be…
    comment by DuskStar · 2020-01-22 · in Go's Tooling Is an Undervalued Technology
  25. Almost every large Go codebase does this with very few exceptions. Until the advent of github.com/pkg/errors there wasn't an easy way to uniformly implement error chaining so people would just prepend strings (if they have any context at…
  26. …errors.Is(error) bool and errors.As(error, interface{}) bool and also errors.Unwrap(error) error. Package github.com/pkg/errors, which I use, only has function errors.Cause(error) error, but writing your own inspection helpers is trivial .…
    comment by ainar-g · 2019-11-10 · in Go Turns 10
  27. …as well. See, for example, how Rob Pike et al. do error handling in their Upspin project[1] or the popular github.com/pkg/errors module[2]. Can you do that with exceptions? Of course! The problem is that suddenly your code will start to…
    comment by ainar-g · 2019-11-08 · in Go Turns 10
  28. …stacktraces, but are not the way to get stack traces. runtime/debug has the API to generate stacktraces. github.com/pkg/errors is the ubiquitous library for seamlessly including stacktraces in errors
    comment by omegabravo · 2019-10-20 · in Working with Errors in Go 1.13
  29. …and that could get expensive. I have heard that performance is the reason but I'm not able to confirm that. github.com/pkg/errors is fairly ubiquitous and includes stack traces. > If everyone needs to do it, why not standardize The only…
    comment by omegabravo · 2019-10-20 · in Working with Errors in Go 1.13
  30. github.com/pkg/errors is a popular solution to this problem
    comment by alecthomas · 2019-10-19 · in Working with Errors in Go 1.13
  31. …be built into the language. Can anyone enlighten me? Edit: Forgot to include the reference: [0] https://github.com/pkg/errors
    comment by malisper · 2019-10-19 · in Working with Errors in Go 1.13
  32. …ooglesource.com/proposal/+/master/design/29934-e... [2] https://github.com/golang/go/issues/29934 [3] https://github.com/pkg/errors [4] https://github.com/pkg/errors/tree/c978824
    comment by guessmyname · 2019-10-19 · in Working with Errors in Go 1.13
  33. IMHO they should either just adopt Dave Cheney's errors package ( https://github.com/pkg/errors ) into the standard library or leave it as it is becoming the de-facto standard. The parallel reddit thread seems to agree too:…
    comment by voidlogic · 2019-04-30 · in Go 1.13: xerrors
  34. +1 on all of this. I really prefer that https://github.com/pkg/errors is outside of the standard library so I don't need to use the fmt.Errorf abomination.
    comment by TheSwordsman · 2019-04-29 · in Go 1.13: xerrors
  35. …to pull in the best bits of Dave Cheney's errors package (which I love) into the standard library: https://github.com/pkg/errors Standardising error unwrapping is a great idea IMHO and I think that this has a lot of merit. I don't like the…
    comment by nickcw · 2019-04-29 · in Go 1.13: xerrors
  36. …is functional. The fact that Go supports neither out-of-the-box is a frustrating waste of time. [1] https://github.com/pkg/errors
    comment by nprateem · 2019-04-06 · in Error Handling in Go (2016)
  37. …with: [...] go: downloading github.com/mewmew/float v0.0.0-20181121163145-c0f786d7da73 go: downloading github.com/pkg/errors v0.8.0 go: downloading github.com/rickypai/natsort v0.0.0-20180124032556-f194e6bd5b0c @$const_str = global [16 x…
  38. The errors package is really useful for generating stack traces in Go 1: https://godoc.org/github.com/pkg/errors
    comment by h2j24 · 2018-10-15 · in Go 2.0 Error Handling Requirements
  39. …get .map_err() -- because that's something you can only really do if you have a Result type. [1]: https://github.com/pkg/errors
  40. …want every error handled the exact same way, and don't have any requirement to add context the way https://github.com/pkg/errors does.
    comment by spyspy · 2018-08-28 · in Go 2 Draft Designs
  41. Just using WithStack() from "github.com/pkg/errors" on any error that originates from outside my repository has been my go-to rule for any Go project. It has never disappointed.
  42. …for the "provide a helpful error message for non-programmers" problem. --- this is why stuff like https://github.com/pkg/errors exists. wrap at the deepest level / where the error originates, and it's relatively rare that you need to add…
  43. …to do so in issues on GitHub) FWIW the errors package is a nice way to further annotate errors: https://github.com/pkg/errors And at least with distributed systems error handling is a more complicated affair. The boilerplate ends up not…
    comment by cdoxsey · 2018-08-10 · in On the uses and misuses of panics in Go
  44. …for me, either. I can easily handle different `error` types and if I want to provide more context I pull in github.com/pkg/errors > gofmt gofmt is great > go test go test has been totally sufficient for me and I was quickly writing and…
  45. …packages. It is somewhat working today. The underlying mechanism is when you type something like: import "github.com/pkg/errors" A .go wrapper file is generated, a Go plugin is built, and then loaded into the ng executable. You can then…
    comment by crawshaw · 2017-11-04 · in Neugram – Scripting in Go
  46. …originated. Go errors don't have this and it costs me a lot of time debugging things. https://godoc.org/github.com/pkg/errors helps, but it's still more of a pain than it should be.
    comment by throw4625 · 2017-08-25 · in Go 1.9 is released
  47. …your errors you can use errors.Wrap()[1]. This repo should replace the stdlib errors package. 1. https://github.com/pkg/errors/blob/master/errors.go#L180
  48. …that your application can't continue anyways because it's broken) You should really use a library like github.com/pkg/errors so you get to wrap the error you return with additional information. Errors are just a worse Either monad after…
    comment by cube2222 · 2017-02-05 · in The State of Go
  49. Check out https://github.com/pkg/errors
    comment by bjacokes · 2017-01-19 · in My Go Resolutions for 2017
  50. There was a proposal at some point to integrate github.com/pkg/errors into the stdlib, since it's pretty much a drop-in replacement to the current errors package, with extras. One of them is that errors contain stack traces that can be…
    comment by saturn_vk · 2017-01-18 · in My Go Resolutions for 2017