-
-
Notifications
You must be signed in to change notification settings - Fork 657
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
zellij-server/src/screen: improve error handling #1770
Conversation
5948ead
to
3095c3f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, thanks for picking this up!
I added some suggestions to the code. In particular: Could you please rephrase the error contexts you introduced? You can have a look at the docs if it helps you. Consider for example the message "failed to send message to server": You introduced it twice, in different portions of the code, but attached to the same function (send_to_server
). If I see this error after zellij crashed and search for it, I will find it in two different locations. How do I know where the error happened then?
You observation on the Option
types in move_clients_from_closed_tab
is correct, the code here already checks for the necessary pre-conditions. I don't think we need to take further actions there.
self.bus | ||
.senders | ||
.send_to_server(ServerInstruction::UnblockInputThread) | ||
.unwrap(); | ||
.context("failed to send message to server") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should rephrase it to say something about what we tried to do when we got that error (When in doubt, refer to the function name). Ideally, send_to_server
already returns an error that tells us something like "failed to deliver message" or so.
I'll go on a bit of a hunt to see whether that's actually the case. If it isn't, I think we should attach this particular bit of context inside the call to send_to_server
(to keep us from replicating it across the codebase. This function is used rather often).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't seem like send_to_server
(and other similar functions) are attaching that kind of context to the error. In order to support that we'd need to change the return type for those but it'll definitely break patterns like these
zellij/zellij-server/src/screen.rs
Lines 835 to 840 in 716f606
.or_else(|err| { | |
let (_, error_context) = err.0; | |
Err(anyhow!("failed to send data to plugins")) | |
.context(error_context) | |
.context("failed to update tabs") | |
})?; |
I'll probably try to see how many places with this type of usage you have
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, it's just one place where it's used that way. Interestingly, I had to move this piece of code into send_to_pty
because of missing traits for it's instruction. Not sure if it makes it better but I guess it's easier for you to take a look at the implementation and for me to revert that particular commit if it doesn't work that to operate on theory
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@arriven Yeah, that's a funny story. It stems from the fact that the PluginInstruction
we send there is an enum, where one of its variants holds a mpsc::Sender
. anyhow
s .context
& friends requires the error types they get to be 'static + Send + Sync
(And in our case the error type is SendError<(PluginInstruction, _)>
), but mpsc::Sender
is !Sync
. That's why I made use of this "crutch" instead and construct an anyhow::Error
from scratch. It's not pretty to look at, but it needn't be imo.
Okay, your changes look very good to me! I like how you rephrased and rewrote the docs, I think it's much clearer now than it was before, thanks. I would prefer if we handle the changes to .or_else(|err| {
let (_, error_context) = err.0;
Err(anyhow!("failed to send data to plugin"))
.context(error_context)
}) but also make use of the Once you revert that commit and CI passes, this PR is good to go! |
P.S.: I see the CI doesn't like your formatting. I recommend you run Also refer to our documentation about building here: https://github.com/zellij-org/zellij/blob/main/CONTRIBUTING.md#building |
8bc1b88
to
bbf349a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very good, thank you!
@har7an I had to use |
That's interesting. I just ran |
Yes, I'm fairly certain that it's not related. All the errors are coming from
so that might be my cargo make not picking some kind of parameter that's supposed to disable that warning but there's also an error about using |
That's weird... We'll see what the CI has to say about that. If all checks pass here, feel free to open the issue and have a closer look!
|
Yeah, it's definitely something with my setup. I decided to look into that rabbit hole of errors and after fixing errors in zellij-utils, zellij-client, and zellij-server (each step was unlocked only after you complete previous one 😃 ) it started complaining about issues in dependencies, and on contrary to issues in actual workspace those ones don't seem to make a lot of sense, i.e.: error[E0412]: cannot find type `Result` in this scope
--> /home/arriven/.cargo/registry/src/github.com-1ecc6299db9ec823/once_cell-1.12.0/src/race.rs:271:28
|
271 | F: FnOnce() -> Result<Box<T>, E>,
| ^^^^^^ not found in this scope As for versions, I have the following:
I should probably try it with your nix setup to have proper versions of dependencies first |
Yeah well that error really doesn't make any sense. Maybe try a I'm sure you'll figure it out, though. Thanks for contributing! :) |
Got rid of last
unwrap()
calls on result, replacing them with error propagation. The onlyunwrap()
left are onOption
type which would be converted intofatal()
anyway since the code already checks for the corresponding condition in that same function (move_clients_from_closed_tab
)WIP #1753