Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Panics should never happen in a library #40

Open
pcman312 opened this issue Jul 17, 2017 · 0 comments
Open

Panics should never happen in a library #40

pcman312 opened this issue Jul 17, 2017 · 0 comments

Comments

@pcman312
Copy link
Contributor

Panicking in a library is an anti-pattern in Go. It results in indeterministic and unpredictable code. The caller has no idea when a library is going to panic unless they are experts in the library's codebase.

Currently, this is being done in several places:

panic("gcache: size <= 0")

gcache/cache.go

Line 163 in bbe6d2a

panic("gcache: Unknown type " + cb.tp)

I believe a better option would be to allow for any size in the New() function, but then checking it in the Build() and returning an error. This makes it more idiomatic and removes the possibility that the caller's program crashes unexpectedly because of a bad input.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant