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

zellij-server: improve thread_bus error handling #1775

Merged
merged 3 commits into from
Oct 7, 2022

Conversation

arriven
Copy link
Contributor

@arriven arriven commented Oct 4, 2022

WIP: #1753

As suggested in my previous PR, moving thread_bus error changes to a separate one

@arriven arriven temporarily deployed to cachix October 4, 2022 09:49 Inactive
Copy link
Contributor

@har7an har7an left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for continuing your work on this!

I left a remark below, do you mind applying it to your other changes, too? That'd be awesome (and very helpful for debugging).

Comment on lines 34 to 38
.as_ref()
.unwrap()
.send(instruction)
.context("failed to send message to screen")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think we can get rid of the unwrap() attached to as_ref, too? Now that we already return a Result we may as well report that error case.

Also what do you think about adding the instruction we sent to the error message, similar to how you already do in send_to_plugin? It may not be helpful for the user, but maybe a developer can make sense of all the content.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point about .as_ref().unwrap()

As for including instruction in other errors, I was assuming that their existing serialization already does that but let me check to be sure

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

upd: crossbeam::channel::SendError doesn't format the content so yes, that pattern would be helpful for devs. Also I've noticed you've added it as a function on the type so I've moved the usage of .to_anyhow() into those thread_bus functions, hope you don't mind

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't mind at all, well done. And thanks for doing the research!

@arriven arriven temporarily deployed to cachix October 6, 2022 13:27 Inactive
@arriven arriven requested a review from har7an October 6, 2022 13:32
Copy link
Contributor

@har7an har7an left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, it looks very polished now!

One last thing: I implemented to_anyhow back then for use with to_client, hence the message states "failed to send message to client ...". Could you reword it to something more generic like "failed to send instruction: ..." instead? That way it doesn't feel "out of place" when e.g. we really tried to send to the server.

Now I'm curious: Do you think you can provoke an error in one of the senders and paste it here so we get a glimpse of what it looks like? For the sake of testing it, you could inject an early return into one of the ScreenInstruction handling functions, maybe in screen.rs:1787:

   2                 screen.render()?;
   1                 screen.unblock_input()?;
1788                 return Ok(());
   1             },
   2             ScreenInstruction::RightClick(point, client_id) => {

and then inject a fatal in route.rs:494 like so:

  5         Action::LeftMouseRelease(point) => {
  4             use zellij_utils::errors::FatalError;
  3             session
  2                 .senders
  1                 .send_to_screen(ScreenInstruction::LeftMouseRelease(point, client_id))
495                 .fatal();
  1         },

and then start zellij and do a left click somewhere in the terminal. That should cause an error.

.as_ref()
.context("failed to get screen sender")?
.send(instruction)
.to_anyhow()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, initially I implemented it as a crutch for the changes in tab, as you noticed correctly. Thank you for removing it in tab!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean, it refused to compile otherwise since anyhow::Result<T> != Result<T, crossbeam::channel::SendError> but thanks! 😅

@arriven arriven temporarily deployed to cachix October 6, 2022 17:05 Inactive
@arriven
Copy link
Contributor Author

arriven commented Oct 6, 2022

sure, the error looks like this

 
Error occurred in server:

  × Thread 'server_router' panicked.
  ├─▶ Originating Thread(s)
  │     1. stdin_handler_thread: AcceptInput
  │   
  ├─▶ At zellij-server/src/route.rs:495:18
  ╰─▶ Program terminates: a fatal error occured
      
      Caused by:
          0: failed to send message to screen
          1: Originating Thread(s)
                1. stdin_handler_thread: AcceptInput
      
          2: failed to send message to channel: LeftMouseRelease(
                 Position {
                     line: Line(
                         3,
                     ),
                     column: Column(
                         54,
                     ),
                 },
                 1,
             )
      

It's even better in the terminal due to coloring but I don't think github would be able to show that 😅

@arriven arriven requested a review from har7an October 6, 2022 17:10
Copy link
Contributor

@har7an har7an left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, I think it looks great now. Thanks for your contribution!

@har7an har7an added the hacktoberfest-accepted PRs counting towards hacktoberfest label Oct 7, 2022
@har7an har7an merged commit 39f33a9 into zellij-org:main Oct 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hacktoberfest-accepted PRs counting towards hacktoberfest
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants