-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Get rid of a lot of error handling #3887
Comments
That sounds good to me. So long as we don't end up with a big uptick in run-time panics caused by issues that aren't unrecoverable errors, cos that would be annoying for a user. |
In my opinion it's not so much a distinction between recoverable or unrecoverable, but between programming errors and legit runtime errors. An error resulting from a programming mistake could be recoverable, but that's no reason not to panic anyway. It's a good thing that it crashes, so that users report these and we can fix them more quickly. |
So long as the programming error is indeed easy to fix! For example if it turned out that we have a bunch of programming errors that lead to intermittent, hard to debug, concurrency issues which causes everybody to start getting panics, that would be bad. But perhaps I'm using a more broad definition of programming error than you. |
That's very well possible. I'm mostly thinking about violated preconditions in a design-by-contract situation, e.g. this one. There's a grey zone, of course. For instance, However, I still think returning an error (and eventually showing it to the user in a panel) is not the right thing to do here. We can decide to be graceful about certain things instead of panicking, but we should never return errors for them. |
I agree with that |
And sometimes it's not totally clear how to decide this. For example, func (v *View) SetOriginX(x int) error {
if x < 0 {
return ErrInvalidPoint
}
v.ox = x
return nil
} This could either
What's best? I tend to think clamping is probably best. |
I agree. I guess because view-layer stuff is just not very critical. |
How do you feel about changing gocui? When I wrote this issue I was mostly thinking about code in lazygit, but cleaning up these would be nice too. That would be a breaking change for other projects using gocui though (lazydocker, lazynpm), and I'm not keen on adapting these... |
I'm fine to go and fix up lazydocker next time I make changes to it. And lazynpm is on life support anyway |
Error handling in go is cumbersome and noisy, and I'd like to restrict it to cases where real errors can occur (e.g. IO or network errors, or errors from calling external tools, etc.).
Sometimes we have controller code that wants to call 4 things in a row, all of which can return errors. This kind of situation is problematic for two reasons:
Now, a lot of functions in the lazygit code base return errors, but these can only occur when the function is called with invalid arguments (e.g. calling SetCurrentView with a view name that doesn't exist). These are programming errors, so it makes little sense to report them to the user; we might as well panic right away. This is closer to an
assert
call in other languages.So I'm proposing to get rid of the error return values of most of the UI-related functions like
HandleFocus
,HandleRender
,ContextMgr.Push
, etc., turning any error conditions inside these into panics. This should simplify a lot of lazygit's code.Opinions welcome.
The text was updated successfully, but these errors were encountered: