ggit icon indicating copy to clipboard operation
ggit copied to clipboard

make it panic less

Open themihai opened this issue 9 years ago • 2 comments

Is the panic everywhere on purpose?

themihai avatar Feb 12 '16 13:02 themihai

To be honest, I can't recall whether we considered the panics to be preferable or just a shortcut, at the time.

But I'd love to have a stronger opinion about the decision one way or the other. Do you think you'd be up for sharing some thoughts on what would make error values a better call here? (Any particular examples that have been a nuisance?)

MikeBosw avatar Feb 12 '16 20:02 MikeBosw

As far as I know the panics are supposed to be exceptional cases but in this project they seem to be the norm. On a web service it could terminate the program/server. You can recover but again that's supposed to be used in exceptional cases so that you can catch "unexpected" panics not ordinary errors. I think a better approach would be to use a custom error type if you need more data. See for example https://golang.org/pkg/net/url/#Error . That way you have context information and you can also terminate the program/call cleanly. Another use cases is testing. You don't want your test suite to panic... It's also worth to note that the official recommendation is to return errors.

https://github.com/golang/go/wiki/PanicAndRecover

themihai avatar Feb 13 '16 11:02 themihai