From 4ca595df6fb22597fbd6393473df0edd6de4b3bd Mon Sep 17 00:00:00 2001 From: pingao Date: Tue, 18 Oct 2022 18:15:40 +0800 Subject: [PATCH 1/5] improve error handling in route --- zellij-server/src/route.rs | 275 +++++++++---------------- zellij-server/src/unit/screen_tests.rs | 3 +- 2 files changed, 102 insertions(+), 176 deletions(-) diff --git a/zellij-server/src/route.rs b/zellij-server/src/route.rs index d516949921..f1e43e5ae8 100644 --- a/zellij-server/src/route.rs +++ b/zellij-server/src/route.rs @@ -10,6 +10,7 @@ use crate::{ use zellij_utils::{ channels::SenderWithContext, data::Event, + errors::prelude::*, input::{ actions::{Action, Direction, ResizeDirection, SearchDirection, SearchOption}, command::TerminalAction, @@ -26,7 +27,7 @@ pub(crate) fn route_action( _os_input: &dyn ServerOsApi, to_server: &SenderWithContext, client_id: ClientId, -) -> bool { +) -> Result { let mut should_break = false; // forward the action to plugins unless it is a mousehold @@ -35,14 +36,11 @@ pub(crate) fn route_action( match action { Action::MouseHoldLeft(..) | Action::MouseHoldRight(..) => {}, _ => { - session - .senders - .send_to_plugin(PluginInstruction::Update( - None, - Some(client_id), - Event::InputReceived, - )) - .unwrap(); + session.senders.send_to_plugin(PluginInstruction::Update( + None, + Some(client_id), + Event::InputReceived, + ))?; }, } @@ -50,29 +48,24 @@ pub(crate) fn route_action( Action::ToggleTab => { session .senders - .send_to_screen(ScreenInstruction::ToggleTab(client_id)) - .unwrap(); + .send_to_screen(ScreenInstruction::ToggleTab(client_id))?; }, Action::Write(val) => { session .senders - .send_to_screen(ScreenInstruction::ClearScroll(client_id)) - .unwrap(); + .send_to_screen(ScreenInstruction::ClearScroll(client_id))?; session .senders - .send_to_screen(ScreenInstruction::WriteCharacter(val, client_id)) - .unwrap(); + .send_to_screen(ScreenInstruction::WriteCharacter(val, client_id))?; }, Action::WriteChars(val) => { session .senders - .send_to_screen(ScreenInstruction::ClearScroll(client_id)) - .unwrap(); + .send_to_screen(ScreenInstruction::ClearScroll(client_id))?; let val = val.into_bytes(); session .senders - .send_to_screen(ScreenInstruction::WriteCharacter(val, client_id)) - .unwrap(); + .send_to_screen(ScreenInstruction::WriteCharacter(val, client_id))?; }, Action::SwitchToMode(mode) => { let attrs = &session.client_attributes; @@ -80,25 +73,18 @@ pub(crate) fn route_action( // this is left here as a stop gap measure until we shift some code around // to allow for this // TODO: Need access to `ClientAttributes` here - session - .senders - .send_to_plugin(PluginInstruction::Update( - None, - Some(client_id), - Event::ModeUpdate(get_mode_info(mode, attrs, session.capabilities)), - )) - .unwrap(); + session.senders.send_to_plugin(PluginInstruction::Update( + None, + Some(client_id), + Event::ModeUpdate(get_mode_info(mode, attrs, session.capabilities)), + ))?; session .senders .send_to_screen(ScreenInstruction::ChangeMode( get_mode_info(mode, attrs, session.capabilities), client_id, - )) - .unwrap(); - session - .senders - .send_to_screen(ScreenInstruction::Render) - .unwrap(); + ))?; + session.senders.send_to_screen(ScreenInstruction::Render)?; }, Action::Resize(direction) => { let screen_instr = match direction { @@ -109,26 +95,17 @@ pub(crate) fn route_action( ResizeDirection::Increase => ScreenInstruction::ResizeIncrease(client_id), ResizeDirection::Decrease => ScreenInstruction::ResizeDecrease(client_id), }; - session.senders.send_to_screen(screen_instr).unwrap(); - }, - Action::SwitchFocus => { - session - .senders - .send_to_screen(ScreenInstruction::SwitchFocus(client_id)) - .unwrap(); - }, - Action::FocusNextPane => { - session - .senders - .send_to_screen(ScreenInstruction::FocusNextPane(client_id)) - .unwrap(); - }, - Action::FocusPreviousPane => { - session - .senders - .send_to_screen(ScreenInstruction::FocusPreviousPane(client_id)) - .unwrap(); - }, + session.senders.send_to_screen(screen_instr)?; + }, + Action::SwitchFocus => session + .senders + .send_to_screen(ScreenInstruction::SwitchFocus(client_id))?, + Action::FocusNextPane => session + .senders + .send_to_screen(ScreenInstruction::FocusNextPane(client_id))?, + Action::FocusPreviousPane => session + .senders + .send_to_screen(ScreenInstruction::FocusPreviousPane(client_id))?, Action::MoveFocus(direction) => { let screen_instr = match direction { Direction::Left => ScreenInstruction::MoveFocusLeft(client_id), @@ -136,7 +113,7 @@ pub(crate) fn route_action( Direction::Up => ScreenInstruction::MoveFocusUp(client_id), Direction::Down => ScreenInstruction::MoveFocusDown(client_id), }; - session.senders.send_to_screen(screen_instr).unwrap(); + session.senders.send_to_screen(screen_instr)?; }, Action::MoveFocusOrTab(direction) => { let screen_instr = match direction { @@ -145,7 +122,7 @@ pub(crate) fn route_action( Direction::Up => ScreenInstruction::SwitchTabNext(client_id), Direction::Down => ScreenInstruction::SwitchTabPrev(client_id), }; - session.senders.send_to_screen(screen_instr).unwrap(); + session.senders.send_to_screen(screen_instr)?; }, Action::MovePane(direction) => { let screen_instr = match direction { @@ -155,85 +132,72 @@ pub(crate) fn route_action( Some(Direction::Down) => ScreenInstruction::MovePaneDown(client_id), None => ScreenInstruction::MovePane(client_id), }; - session.senders.send_to_screen(screen_instr).unwrap(); + session.senders.send_to_screen(screen_instr)?; }, - Action::DumpScreen(val, full) => { + Action::DumpScreen(val) => { session .senders - .send_to_screen(ScreenInstruction::DumpScreen(val, client_id, full)) - .unwrap(); + .send_to_screen(ScreenInstruction::DumpScreen(val, client_id))?; }, Action::EditScrollback => { session .senders - .send_to_screen(ScreenInstruction::EditScrollback(client_id)) - .unwrap(); + .send_to_screen(ScreenInstruction::EditScrollback(client_id))?; }, Action::ScrollUp => { session .senders - .send_to_screen(ScreenInstruction::ScrollUp(client_id)) - .unwrap(); + .send_to_screen(ScreenInstruction::ScrollUp(client_id))?; }, Action::ScrollUpAt(point) => { session .senders - .send_to_screen(ScreenInstruction::ScrollUpAt(point, client_id)) - .unwrap(); + .send_to_screen(ScreenInstruction::ScrollUpAt(point, client_id))?; }, Action::ScrollDown => { session .senders - .send_to_screen(ScreenInstruction::ScrollDown(client_id)) - .unwrap(); + .send_to_screen(ScreenInstruction::ScrollDown(client_id))?; }, Action::ScrollDownAt(point) => { session .senders - .send_to_screen(ScreenInstruction::ScrollDownAt(point, client_id)) - .unwrap(); + .send_to_screen(ScreenInstruction::ScrollDownAt(point, client_id))?; }, Action::ScrollToBottom => { session .senders - .send_to_screen(ScreenInstruction::ScrollToBottom(client_id)) - .unwrap(); + .send_to_screen(ScreenInstruction::ScrollToBottom(client_id))?; }, Action::PageScrollUp => { session .senders - .send_to_screen(ScreenInstruction::PageScrollUp(client_id)) - .unwrap(); + .send_to_screen(ScreenInstruction::PageScrollUp(client_id))?; }, Action::PageScrollDown => { session .senders - .send_to_screen(ScreenInstruction::PageScrollDown(client_id)) - .unwrap(); + .send_to_screen(ScreenInstruction::PageScrollDown(client_id))?; }, Action::HalfPageScrollUp => { session .senders - .send_to_screen(ScreenInstruction::HalfPageScrollUp(client_id)) - .unwrap(); + .send_to_screen(ScreenInstruction::HalfPageScrollUp(client_id))?; }, Action::HalfPageScrollDown => { session .senders - .send_to_screen(ScreenInstruction::HalfPageScrollDown(client_id)) - .unwrap(); + .send_to_screen(ScreenInstruction::HalfPageScrollDown(client_id))?; }, Action::ToggleFocusFullscreen => { session .senders - .send_to_screen(ScreenInstruction::ToggleActiveTerminalFullscreen(client_id)) - .unwrap(); + .send_to_screen(ScreenInstruction::ToggleActiveTerminalFullscreen(client_id))?; }, Action::TogglePaneFrames => { session .senders - .send_to_screen(ScreenInstruction::TogglePaneFrames) - .unwrap(); + .send_to_screen(ScreenInstruction::TogglePaneFrames)?; }, Action::NewPane(direction, name) => { let shell = session.default_shell.clone(); @@ -258,7 +222,7 @@ pub(crate) fn route_action( ClientOrTabIndex::ClientId(client_id), ), }; - session.senders.send_to_pty(pty_instr).unwrap(); + session.senders.send_to_pty(pty_instr)?; }, Action::EditFile(path_to_file, line_number, split_direction, should_float) => { let title = format!("Editing: {}", path_to_file.display()); @@ -288,41 +252,34 @@ pub(crate) fn route_action( ClientOrTabIndex::ClientId(client_id), ), }; - session.senders.send_to_pty(pty_instr).unwrap(); + session.senders.send_to_pty(pty_instr)?; }, Action::SwitchModeForAllClients(input_mode) => { let attrs = &session.client_attributes; - session - .senders - .send_to_plugin(PluginInstruction::Update( - None, - None, - Event::ModeUpdate(get_mode_info(input_mode, attrs, session.capabilities)), - )) - .unwrap(); + session.senders.send_to_plugin(PluginInstruction::Update( + None, + None, + Event::ModeUpdate(get_mode_info(input_mode, attrs, session.capabilities)), + ))?; session .senders .send_to_screen(ScreenInstruction::ChangeModeForAllClients(get_mode_info( input_mode, attrs, session.capabilities, - ))) - .unwrap(); + )))?; }, Action::NewFloatingPane(run_command, name) => { let should_float = true; let run_cmd = run_command .map(|cmd| TerminalAction::RunCommand(cmd.into())) .or_else(|| session.default_shell.clone()); - session - .senders - .send_to_pty(PtyInstruction::SpawnTerminal( - run_cmd, - Some(should_float), - name, - ClientOrTabIndex::ClientId(client_id), - )) - .unwrap(); + session.senders.send_to_pty(PtyInstruction::SpawnTerminal( + run_cmd, + Some(should_float), + name, + ClientOrTabIndex::ClientId(client_id), + ))?; }, Action::NewTiledPane(direction, run_command, name) => { let should_float = false; @@ -350,13 +307,12 @@ pub(crate) fn route_action( ClientOrTabIndex::ClientId(client_id), ), }; - session.senders.send_to_pty(pty_instr).unwrap(); + session.senders.send_to_pty(pty_instr)?; }, Action::TogglePaneEmbedOrFloating => { session .senders - .send_to_screen(ScreenInstruction::TogglePaneEmbedOrFloating(client_id)) - .unwrap(); + .send_to_screen(ScreenInstruction::TogglePaneEmbedOrFloating(client_id))?; }, Action::ToggleFloatingPanes => { session @@ -364,20 +320,17 @@ pub(crate) fn route_action( .send_to_screen(ScreenInstruction::ToggleFloatingPanes( client_id, session.default_shell.clone(), - )) - .unwrap(); + ))?; }, Action::PaneNameInput(c) => { session .senders - .send_to_screen(ScreenInstruction::UpdatePaneName(c, client_id)) - .unwrap(); + .send_to_screen(ScreenInstruction::UpdatePaneName(c, client_id))?; }, Action::UndoRenamePane => { session .senders - .send_to_screen(ScreenInstruction::UndoRenamePane(client_id)) - .unwrap(); + .send_to_screen(ScreenInstruction::UndoRenamePane(client_id))?; }, Action::Run(command) => { let run_cmd = Some(TerminalAction::RunCommand(command.clone().into())); @@ -402,155 +355,126 @@ pub(crate) fn route_action( ClientOrTabIndex::ClientId(client_id), ), }; - session.senders.send_to_pty(pty_instr).unwrap(); + session.senders.send_to_pty(pty_instr)?; }, Action::CloseFocus => { session .senders - .send_to_screen(ScreenInstruction::CloseFocusedPane(client_id)) - .unwrap(); + .send_to_screen(ScreenInstruction::CloseFocusedPane(client_id))?; }, Action::NewTab(tab_layout, tab_name) => { let shell = session.default_shell.clone(); - session - .senders - .send_to_pty(PtyInstruction::NewTab( - shell, tab_layout, tab_name, client_id, - )) - .unwrap(); + session.senders.send_to_pty(PtyInstruction::NewTab( + shell, tab_layout, tab_name, client_id, + ))?; }, Action::GoToNextTab => { session .senders - .send_to_screen(ScreenInstruction::SwitchTabNext(client_id)) - .unwrap(); + .send_to_screen(ScreenInstruction::SwitchTabNext(client_id))?; }, Action::GoToPreviousTab => { session .senders - .send_to_screen(ScreenInstruction::SwitchTabPrev(client_id)) - .unwrap(); + .send_to_screen(ScreenInstruction::SwitchTabPrev(client_id))?; }, Action::ToggleActiveSyncTab => { session .senders - .send_to_screen(ScreenInstruction::ToggleActiveSyncTab(client_id)) - .unwrap(); + .send_to_screen(ScreenInstruction::ToggleActiveSyncTab(client_id))?; }, Action::CloseTab => { session .senders - .send_to_screen(ScreenInstruction::CloseTab(client_id)) - .unwrap(); + .send_to_screen(ScreenInstruction::CloseTab(client_id))?; }, Action::GoToTab(i) => { session .senders - .send_to_screen(ScreenInstruction::GoToTab(i, Some(client_id))) - .unwrap(); + .send_to_screen(ScreenInstruction::GoToTab(i, Some(client_id)))?; }, Action::TabNameInput(c) => { session .senders - .send_to_screen(ScreenInstruction::UpdateTabName(c, client_id)) - .unwrap(); + .send_to_screen(ScreenInstruction::UpdateTabName(c, client_id))?; }, Action::UndoRenameTab => { session .senders - .send_to_screen(ScreenInstruction::UndoRenameTab(client_id)) - .unwrap(); + .send_to_screen(ScreenInstruction::UndoRenameTab(client_id))?; }, Action::Quit => { - to_server - .send(ServerInstruction::ClientExit(client_id)) - .unwrap(); + to_server.send(ServerInstruction::ClientExit(client_id))?; should_break = true; }, Action::Detach => { - to_server - .send(ServerInstruction::DetachSession(vec![client_id])) - .unwrap(); + to_server.send(ServerInstruction::DetachSession(vec![client_id]))?; should_break = true; }, Action::LeftClick(point) => { session .senders - .send_to_screen(ScreenInstruction::LeftClick(point, client_id)) - .unwrap(); + .send_to_screen(ScreenInstruction::LeftClick(point, client_id))?; }, Action::RightClick(point) => { session .senders - .send_to_screen(ScreenInstruction::RightClick(point, client_id)) - .unwrap(); + .send_to_screen(ScreenInstruction::RightClick(point, client_id))?; }, Action::MiddleClick(point) => { session .senders - .send_to_screen(ScreenInstruction::MiddleClick(point, client_id)) - .unwrap(); + .send_to_screen(ScreenInstruction::MiddleClick(point, client_id))?; }, Action::LeftMouseRelease(point) => { session .senders - .send_to_screen(ScreenInstruction::LeftMouseRelease(point, client_id)) - .unwrap(); + .send_to_screen(ScreenInstruction::LeftMouseRelease(point, client_id))?; }, Action::RightMouseRelease(point) => { session .senders - .send_to_screen(ScreenInstruction::RightMouseRelease(point, client_id)) - .unwrap(); + .send_to_screen(ScreenInstruction::RightMouseRelease(point, client_id))?; }, Action::MiddleMouseRelease(point) => { session .senders - .send_to_screen(ScreenInstruction::MiddleMouseRelease(point, client_id)) - .unwrap(); + .send_to_screen(ScreenInstruction::MiddleMouseRelease(point, client_id))?; }, Action::MouseHoldLeft(point) => { session .senders - .send_to_screen(ScreenInstruction::MouseHoldLeft(point, client_id)) - .unwrap(); + .send_to_screen(ScreenInstruction::MouseHoldLeft(point, client_id))?; }, Action::MouseHoldRight(point) => { session .senders - .send_to_screen(ScreenInstruction::MouseHoldRight(point, client_id)) - .unwrap(); + .send_to_screen(ScreenInstruction::MouseHoldRight(point, client_id))?; }, Action::MouseHoldMiddle(point) => { session .senders - .send_to_screen(ScreenInstruction::MouseHoldMiddle(point, client_id)) - .unwrap(); + .send_to_screen(ScreenInstruction::MouseHoldMiddle(point, client_id))?; }, Action::Copy => { session .senders - .send_to_screen(ScreenInstruction::Copy(client_id)) - .unwrap(); + .send_to_screen(ScreenInstruction::Copy(client_id))?; }, Action::Confirm => { session .senders - .send_to_screen(ScreenInstruction::ConfirmPrompt(client_id)) - .unwrap(); + .send_to_screen(ScreenInstruction::ConfirmPrompt(client_id))?; }, Action::Deny => { session .senders - .send_to_screen(ScreenInstruction::DenyPrompt(client_id)) - .unwrap(); + .send_to_screen(ScreenInstruction::DenyPrompt(client_id))?; }, #[allow(clippy::single_match)] Action::SkipConfirm(action) => match *action { Action::Quit => { - to_server - .send(ServerInstruction::ClientExit(client_id)) - .unwrap(); + to_server.send(ServerInstruction::ClientExit(client_id))?; should_break = true; }, _ => {}, @@ -559,15 +483,14 @@ pub(crate) fn route_action( Action::SearchInput(c) => { session .senders - .send_to_screen(ScreenInstruction::UpdateSearch(c, client_id)) - .unwrap(); + .send_to_screen(ScreenInstruction::UpdateSearch(c, client_id))?; }, Action::Search(d) => { let instruction = match d { SearchDirection::Down => ScreenInstruction::SearchDown(client_id), SearchDirection::Up => ScreenInstruction::SearchUp(client_id), }; - session.senders.send_to_screen(instruction).unwrap(); + session.senders.send_to_screen(instruction)?; }, Action::SearchToggleOption(o) => { let instruction = match o { @@ -577,10 +500,10 @@ pub(crate) fn route_action( SearchOption::WholeWord => ScreenInstruction::SearchToggleWholeWord(client_id), SearchOption::Wrap => ScreenInstruction::SearchToggleWrap(client_id), }; - session.senders.send_to_screen(instruction).unwrap(); + session.senders.send_to_screen(instruction)?; }, } - should_break + Ok(should_break) } // this should only be used for one-off startup instructions @@ -639,7 +562,9 @@ pub(crate) fn route_thread_main( &*os_input, &to_server, client_id, - ) { + ) + .unwrap() + { should_break = true; } } diff --git a/zellij-server/src/unit/screen_tests.rs b/zellij-server/src/unit/screen_tests.rs index 5bbb56b819..287ffab4d8 100644 --- a/zellij-server/src/unit/screen_tests.rs +++ b/zellij-server/src/unit/screen_tests.rs @@ -115,7 +115,8 @@ fn send_cli_action_to_server( &*os_input, &to_server.clone(), client_id, - ); + ) + .unwrap(); } } From 65b7d7b363f1eb5e2475eea06a9fa94a5c395931 Mon Sep 17 00:00:00 2001 From: pingao Date: Wed, 19 Oct 2022 10:25:23 +0800 Subject: [PATCH 2/5] improve error handling in route --- zellij-server/src/lib.rs | 4 +++- zellij-server/src/route.rs | 19 +++++++++---------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/zellij-server/src/lib.rs b/zellij-server/src/lib.rs index 1f642534b4..463e84a66d 100644 --- a/zellij-server/src/lib.rs +++ b/zellij-server/src/lib.rs @@ -35,6 +35,7 @@ use crate::{ wasm_vm::{wasm_thread_main, PluginInstruction}, }; use route::route_thread_main; +use zellij_utils::errors::prelude::Context; use zellij_utils::{ channels::{self, ChannelWithContext, SenderWithContext}, cli::CliArgs, @@ -277,7 +278,8 @@ pub fn start_server(mut os_input: Box, socket_path: PathBuf) { client_id, ) }) - .unwrap(), + .context("Failed to spawn server_router thread") + .fatal(), ); }, Err(err) => { diff --git a/zellij-server/src/route.rs b/zellij-server/src/route.rs index f1e43e5ae8..0fa25cc3a6 100644 --- a/zellij-server/src/route.rs +++ b/zellij-server/src/route.rs @@ -530,7 +530,7 @@ pub(crate) fn route_thread_main( to_server: SenderWithContext, mut receiver: IpcReceiverWithContext, client_id: ClientId, -) { +) -> Result<()> { let mut retry_queue = vec![]; 'route_loop: loop { match receiver.recv() { @@ -539,7 +539,7 @@ pub(crate) fn route_thread_main( let rlocked_sessions = session_data.read().unwrap(); let handle_instruction = |instruction: ClientToServerMsg, mut retry_queue: Option<&mut Vec>| - -> bool { + -> Result { let mut should_break = false; match instruction { ClientToServerMsg::Action(action, maybe_client_id) => { @@ -553,7 +553,7 @@ pub(crate) fn route_thread_main( if send_res.is_err() { let _ = to_server .send(ServerInstruction::RemoveClient(client_id)); - return true; + return Ok(true); } } if route_action( @@ -562,9 +562,7 @@ pub(crate) fn route_thread_main( &*os_input, &to_server, client_id, - ) - .unwrap() - { + )? { should_break = true; } } @@ -648,7 +646,7 @@ pub(crate) fn route_thread_main( // we don't unwrap this because we don't really care if there's an error here (eg. // if the main server thread exited before this router thread did) let _ = to_server.send(ServerInstruction::RemoveClient(client_id)); - return true; + return Ok(true); }, ClientToServerMsg::KillSession => { to_server.send(ServerInstruction::KillSession).unwrap(); @@ -665,16 +663,16 @@ pub(crate) fn route_thread_main( let _ = to_server.send(ServerInstruction::ActiveClients(client_id)); }, } - should_break + Ok(should_break) }; for instruction_to_retry in retry_queue.drain(..) { log::warn!("Server ready, retrying sending instruction."); - let should_break = handle_instruction(instruction_to_retry, None); + let should_break = handle_instruction(instruction_to_retry, None)?; if should_break { break 'route_loop; } } - let should_break = handle_instruction(instruction, Some(&mut retry_queue)); + let should_break = handle_instruction(instruction, Some(&mut retry_queue))?; if should_break { break 'route_loop; } @@ -691,4 +689,5 @@ pub(crate) fn route_thread_main( }, } } + Ok(()) } From d13dbea798f7ec3530b6712d028d6bd6af725b2a Mon Sep 17 00:00:00 2001 From: pingao Date: Fri, 21 Oct 2022 10:33:36 +0800 Subject: [PATCH 3/5] improve error handling in route --- zellij-server/src/lib.rs | 6 +- zellij-server/src/route.rs | 274 ++++++++++++++++++++++++------------- 2 files changed, 179 insertions(+), 101 deletions(-) diff --git a/zellij-server/src/lib.rs b/zellij-server/src/lib.rs index 463e84a66d..fa871f7311 100644 --- a/zellij-server/src/lib.rs +++ b/zellij-server/src/lib.rs @@ -35,7 +35,6 @@ use crate::{ wasm_vm::{wasm_thread_main, PluginInstruction}, }; use route::route_thread_main; -use zellij_utils::errors::prelude::Context; use zellij_utils::{ channels::{self, ChannelWithContext, SenderWithContext}, cli::CliArgs, @@ -276,10 +275,9 @@ pub fn start_server(mut os_input: Box, socket_path: PathBuf) { to_server, receiver, client_id, - ) + ).fatal() }) - .context("Failed to spawn server_router thread") - .fatal(), + .unwrap(), ); }, Err(err) => { diff --git a/zellij-server/src/route.rs b/zellij-server/src/route.rs index 0fa25cc3a6..ad2714a609 100644 --- a/zellij-server/src/route.rs +++ b/zellij-server/src/route.rs @@ -29,6 +29,7 @@ pub(crate) fn route_action( client_id: ClientId, ) -> Result { let mut should_break = false; + let err_context = || format!("failed to route action for client {client_id}"); // forward the action to plugins unless it is a mousehold // this is a bit of a hack around the unfortunate architecture we use with plugins @@ -36,11 +37,14 @@ pub(crate) fn route_action( match action { Action::MouseHoldLeft(..) | Action::MouseHoldRight(..) => {}, _ => { - session.senders.send_to_plugin(PluginInstruction::Update( - None, - Some(client_id), - Event::InputReceived, - ))?; + session + .senders + .send_to_plugin(PluginInstruction::Update( + None, + Some(client_id), + Event::InputReceived, + )) + .with_context(err_context)?; }, } @@ -48,24 +52,29 @@ pub(crate) fn route_action( Action::ToggleTab => { session .senders - .send_to_screen(ScreenInstruction::ToggleTab(client_id))?; + .send_to_screen(ScreenInstruction::ToggleTab(client_id)) + .with_context(err_context)?; }, Action::Write(val) => { session .senders - .send_to_screen(ScreenInstruction::ClearScroll(client_id))?; + .send_to_screen(ScreenInstruction::ClearScroll(client_id)) + .with_context(err_context)?; session .senders - .send_to_screen(ScreenInstruction::WriteCharacter(val, client_id))?; + .send_to_screen(ScreenInstruction::WriteCharacter(val, client_id)) + .with_context(err_context)?; }, Action::WriteChars(val) => { session .senders - .send_to_screen(ScreenInstruction::ClearScroll(client_id))?; + .send_to_screen(ScreenInstruction::ClearScroll(client_id)) + .with_context(err_context)?; let val = val.into_bytes(); session .senders - .send_to_screen(ScreenInstruction::WriteCharacter(val, client_id))?; + .send_to_screen(ScreenInstruction::WriteCharacter(val, client_id)) + .with_context(err_context)?; }, Action::SwitchToMode(mode) => { let attrs = &session.client_attributes; @@ -73,18 +82,25 @@ pub(crate) fn route_action( // this is left here as a stop gap measure until we shift some code around // to allow for this // TODO: Need access to `ClientAttributes` here - session.senders.send_to_plugin(PluginInstruction::Update( - None, - Some(client_id), - Event::ModeUpdate(get_mode_info(mode, attrs, session.capabilities)), - ))?; + session + .senders + .send_to_plugin(PluginInstruction::Update( + None, + Some(client_id), + Event::ModeUpdate(get_mode_info(mode, attrs, session.capabilities)), + )) + .with_context(err_context)?; session .senders .send_to_screen(ScreenInstruction::ChangeMode( get_mode_info(mode, attrs, session.capabilities), client_id, - ))?; - session.senders.send_to_screen(ScreenInstruction::Render)?; + )) + .with_context(err_context)?; + session + .senders + .send_to_screen(ScreenInstruction::Render) + .with_context(err_context)?; }, Action::Resize(direction) => { let screen_instr = match direction { @@ -95,17 +111,26 @@ pub(crate) fn route_action( ResizeDirection::Increase => ScreenInstruction::ResizeIncrease(client_id), ResizeDirection::Decrease => ScreenInstruction::ResizeDecrease(client_id), }; - session.senders.send_to_screen(screen_instr)?; - }, - Action::SwitchFocus => session - .senders - .send_to_screen(ScreenInstruction::SwitchFocus(client_id))?, - Action::FocusNextPane => session - .senders - .send_to_screen(ScreenInstruction::FocusNextPane(client_id))?, - Action::FocusPreviousPane => session - .senders - .send_to_screen(ScreenInstruction::FocusPreviousPane(client_id))?, + session.senders.send_to_screen(screen_instr).with_context(err_context)?; + }, + Action::SwitchFocus => { + session + .senders + .send_to_screen(ScreenInstruction::SwitchFocus(client_id)) + .with_context(err_context)?; + }, + Action::FocusNextPane => { + session + .senders + .send_to_screen(ScreenInstruction::FocusNextPane(client_id)) + .with_context(err_context)?; + }, + Action::FocusPreviousPane => { + session + .senders + .send_to_screen(ScreenInstruction::FocusPreviousPane(client_id)) + .with_context(err_context)?; + }, Action::MoveFocus(direction) => { let screen_instr = match direction { Direction::Left => ScreenInstruction::MoveFocusLeft(client_id), @@ -113,7 +138,7 @@ pub(crate) fn route_action( Direction::Up => ScreenInstruction::MoveFocusUp(client_id), Direction::Down => ScreenInstruction::MoveFocusDown(client_id), }; - session.senders.send_to_screen(screen_instr)?; + session.senders.send_to_screen(screen_instr).with_context(err_context)?; }, Action::MoveFocusOrTab(direction) => { let screen_instr = match direction { @@ -122,7 +147,7 @@ pub(crate) fn route_action( Direction::Up => ScreenInstruction::SwitchTabNext(client_id), Direction::Down => ScreenInstruction::SwitchTabPrev(client_id), }; - session.senders.send_to_screen(screen_instr)?; + session.senders.send_to_screen(screen_instr).with_context(err_context)?; }, Action::MovePane(direction) => { let screen_instr = match direction { @@ -132,72 +157,85 @@ pub(crate) fn route_action( Some(Direction::Down) => ScreenInstruction::MovePaneDown(client_id), None => ScreenInstruction::MovePane(client_id), }; - session.senders.send_to_screen(screen_instr)?; + session.senders.send_to_screen(screen_instr).with_context(err_context)?; }, - Action::DumpScreen(val) => { + Action::DumpScreen(val, full) => { session .senders - .send_to_screen(ScreenInstruction::DumpScreen(val, client_id))?; + .send_to_screen(ScreenInstruction::DumpScreen(val, client_id, full)) + .with_context(err_context)?; }, Action::EditScrollback => { session .senders - .send_to_screen(ScreenInstruction::EditScrollback(client_id))?; + .send_to_screen(ScreenInstruction::EditScrollback(client_id)) + .with_context(err_context)?; }, Action::ScrollUp => { session .senders - .send_to_screen(ScreenInstruction::ScrollUp(client_id))?; + .send_to_screen(ScreenInstruction::ScrollUp(client_id)) + .with_context(err_context)?; }, Action::ScrollUpAt(point) => { session .senders - .send_to_screen(ScreenInstruction::ScrollUpAt(point, client_id))?; + .send_to_screen(ScreenInstruction::ScrollUpAt(point, client_id)) + .with_context(err_context)?; }, Action::ScrollDown => { session .senders - .send_to_screen(ScreenInstruction::ScrollDown(client_id))?; + .send_to_screen(ScreenInstruction::ScrollDown(client_id)) + .with_context(err_context)?; }, Action::ScrollDownAt(point) => { session .senders - .send_to_screen(ScreenInstruction::ScrollDownAt(point, client_id))?; + .send_to_screen(ScreenInstruction::ScrollDownAt(point, client_id)) + .with_context(err_context)?; }, Action::ScrollToBottom => { session .senders - .send_to_screen(ScreenInstruction::ScrollToBottom(client_id))?; + .send_to_screen(ScreenInstruction::ScrollToBottom(client_id)) + .with_context(err_context)?; }, Action::PageScrollUp => { session .senders - .send_to_screen(ScreenInstruction::PageScrollUp(client_id))?; + .send_to_screen(ScreenInstruction::PageScrollUp(client_id)) + .with_context(err_context)?; }, Action::PageScrollDown => { session .senders - .send_to_screen(ScreenInstruction::PageScrollDown(client_id))?; + .send_to_screen(ScreenInstruction::PageScrollDown(client_id)) + .with_context(err_context)?; }, Action::HalfPageScrollUp => { session .senders - .send_to_screen(ScreenInstruction::HalfPageScrollUp(client_id))?; + .send_to_screen(ScreenInstruction::HalfPageScrollUp(client_id)) + .with_context(err_context)?; }, Action::HalfPageScrollDown => { session .senders - .send_to_screen(ScreenInstruction::HalfPageScrollDown(client_id))?; + .send_to_screen(ScreenInstruction::HalfPageScrollDown(client_id)) + .with_context(err_context)?; }, Action::ToggleFocusFullscreen => { session .senders - .send_to_screen(ScreenInstruction::ToggleActiveTerminalFullscreen(client_id))?; + .send_to_screen(ScreenInstruction::ToggleActiveTerminalFullscreen(client_id)) + .with_context(err_context)?; }, Action::TogglePaneFrames => { session .senders - .send_to_screen(ScreenInstruction::TogglePaneFrames)?; + .send_to_screen(ScreenInstruction::TogglePaneFrames) + .with_context(err_context)?; }, Action::NewPane(direction, name) => { let shell = session.default_shell.clone(); @@ -222,7 +260,7 @@ pub(crate) fn route_action( ClientOrTabIndex::ClientId(client_id), ), }; - session.senders.send_to_pty(pty_instr)?; + session.senders.send_to_pty(pty_instr).with_context(err_context)?; }, Action::EditFile(path_to_file, line_number, split_direction, should_float) => { let title = format!("Editing: {}", path_to_file.display()); @@ -252,34 +290,41 @@ pub(crate) fn route_action( ClientOrTabIndex::ClientId(client_id), ), }; - session.senders.send_to_pty(pty_instr)?; + session.senders.send_to_pty(pty_instr).with_context(err_context)?; }, Action::SwitchModeForAllClients(input_mode) => { let attrs = &session.client_attributes; - session.senders.send_to_plugin(PluginInstruction::Update( - None, - None, - Event::ModeUpdate(get_mode_info(input_mode, attrs, session.capabilities)), - ))?; + session + .senders + .send_to_plugin(PluginInstruction::Update( + None, + None, + Event::ModeUpdate(get_mode_info(input_mode, attrs, session.capabilities)), + )) + .with_context(err_context)?; session .senders .send_to_screen(ScreenInstruction::ChangeModeForAllClients(get_mode_info( input_mode, attrs, session.capabilities, - )))?; + ))) + .with_context(err_context)?; }, Action::NewFloatingPane(run_command, name) => { let should_float = true; let run_cmd = run_command .map(|cmd| TerminalAction::RunCommand(cmd.into())) .or_else(|| session.default_shell.clone()); - session.senders.send_to_pty(PtyInstruction::SpawnTerminal( - run_cmd, - Some(should_float), - name, - ClientOrTabIndex::ClientId(client_id), - ))?; + session + .senders + .send_to_pty(PtyInstruction::SpawnTerminal( + run_cmd, + Some(should_float), + name, + ClientOrTabIndex::ClientId(client_id), + )) + .with_context(err_context)?; }, Action::NewTiledPane(direction, run_command, name) => { let should_float = false; @@ -307,12 +352,13 @@ pub(crate) fn route_action( ClientOrTabIndex::ClientId(client_id), ), }; - session.senders.send_to_pty(pty_instr)?; + session.senders.send_to_pty(pty_instr).with_context(err_context)?; }, Action::TogglePaneEmbedOrFloating => { session .senders - .send_to_screen(ScreenInstruction::TogglePaneEmbedOrFloating(client_id))?; + .send_to_screen(ScreenInstruction::TogglePaneEmbedOrFloating(client_id)) + .with_context(err_context)?; }, Action::ToggleFloatingPanes => { session @@ -320,17 +366,20 @@ pub(crate) fn route_action( .send_to_screen(ScreenInstruction::ToggleFloatingPanes( client_id, session.default_shell.clone(), - ))?; + )) + .with_context(err_context)?; }, Action::PaneNameInput(c) => { session .senders - .send_to_screen(ScreenInstruction::UpdatePaneName(c, client_id))?; + .send_to_screen(ScreenInstruction::UpdatePaneName(c, client_id)) + .with_context(err_context)?; }, Action::UndoRenamePane => { session .senders - .send_to_screen(ScreenInstruction::UndoRenamePane(client_id))?; + .send_to_screen(ScreenInstruction::UndoRenamePane(client_id)) + .with_context(err_context)?; }, Action::Run(command) => { let run_cmd = Some(TerminalAction::RunCommand(command.clone().into())); @@ -355,126 +404,155 @@ pub(crate) fn route_action( ClientOrTabIndex::ClientId(client_id), ), }; - session.senders.send_to_pty(pty_instr)?; + session.senders.send_to_pty(pty_instr).with_context(err_context)?; }, Action::CloseFocus => { session .senders - .send_to_screen(ScreenInstruction::CloseFocusedPane(client_id))?; + .send_to_screen(ScreenInstruction::CloseFocusedPane(client_id)) + .with_context(err_context)?; }, Action::NewTab(tab_layout, tab_name) => { let shell = session.default_shell.clone(); - session.senders.send_to_pty(PtyInstruction::NewTab( - shell, tab_layout, tab_name, client_id, - ))?; + session + .senders + .send_to_pty(PtyInstruction::NewTab( + shell, tab_layout, tab_name, client_id, + )) + .with_context(err_context)?; }, Action::GoToNextTab => { session .senders - .send_to_screen(ScreenInstruction::SwitchTabNext(client_id))?; + .send_to_screen(ScreenInstruction::SwitchTabNext(client_id)) + .with_context(err_context)?; }, Action::GoToPreviousTab => { session .senders - .send_to_screen(ScreenInstruction::SwitchTabPrev(client_id))?; + .send_to_screen(ScreenInstruction::SwitchTabPrev(client_id)) + .with_context(err_context)?; }, Action::ToggleActiveSyncTab => { session .senders - .send_to_screen(ScreenInstruction::ToggleActiveSyncTab(client_id))?; + .send_to_screen(ScreenInstruction::ToggleActiveSyncTab(client_id)) + .with_context(err_context)?; }, Action::CloseTab => { session .senders - .send_to_screen(ScreenInstruction::CloseTab(client_id))?; + .send_to_screen(ScreenInstruction::CloseTab(client_id)) + .with_context(err_context)?; }, Action::GoToTab(i) => { session .senders - .send_to_screen(ScreenInstruction::GoToTab(i, Some(client_id)))?; + .send_to_screen(ScreenInstruction::GoToTab(i, Some(client_id))) + .with_context(err_context)?; }, Action::TabNameInput(c) => { session .senders - .send_to_screen(ScreenInstruction::UpdateTabName(c, client_id))?; + .send_to_screen(ScreenInstruction::UpdateTabName(c, client_id)) + .with_context(err_context)?; }, Action::UndoRenameTab => { session .senders - .send_to_screen(ScreenInstruction::UndoRenameTab(client_id))?; + .send_to_screen(ScreenInstruction::UndoRenameTab(client_id)) + .with_context(err_context)?; }, Action::Quit => { - to_server.send(ServerInstruction::ClientExit(client_id))?; + to_server + .send(ServerInstruction::ClientExit(client_id)) + .with_context(err_context)?; should_break = true; }, Action::Detach => { - to_server.send(ServerInstruction::DetachSession(vec![client_id]))?; + to_server + .send(ServerInstruction::DetachSession(vec![client_id])) + .with_context(err_context)?; should_break = true; }, Action::LeftClick(point) => { session .senders - .send_to_screen(ScreenInstruction::LeftClick(point, client_id))?; + .send_to_screen(ScreenInstruction::LeftClick(point, client_id)) + .with_context(err_context)?; }, Action::RightClick(point) => { session .senders - .send_to_screen(ScreenInstruction::RightClick(point, client_id))?; + .send_to_screen(ScreenInstruction::RightClick(point, client_id)) + .with_context(err_context)?; }, Action::MiddleClick(point) => { session .senders - .send_to_screen(ScreenInstruction::MiddleClick(point, client_id))?; + .send_to_screen(ScreenInstruction::MiddleClick(point, client_id)) + .with_context(err_context)?; }, Action::LeftMouseRelease(point) => { session .senders - .send_to_screen(ScreenInstruction::LeftMouseRelease(point, client_id))?; + .send_to_screen(ScreenInstruction::LeftMouseRelease(point, client_id)) + .with_context(err_context)?; }, Action::RightMouseRelease(point) => { session .senders - .send_to_screen(ScreenInstruction::RightMouseRelease(point, client_id))?; + .send_to_screen(ScreenInstruction::RightMouseRelease(point, client_id)) + .with_context(err_context)?; }, Action::MiddleMouseRelease(point) => { session .senders - .send_to_screen(ScreenInstruction::MiddleMouseRelease(point, client_id))?; + .send_to_screen(ScreenInstruction::MiddleMouseRelease(point, client_id)) + .with_context(err_context)?; }, Action::MouseHoldLeft(point) => { session .senders - .send_to_screen(ScreenInstruction::MouseHoldLeft(point, client_id))?; + .send_to_screen(ScreenInstruction::MouseHoldLeft(point, client_id)) + .with_context(err_context)?; }, Action::MouseHoldRight(point) => { session .senders - .send_to_screen(ScreenInstruction::MouseHoldRight(point, client_id))?; + .send_to_screen(ScreenInstruction::MouseHoldRight(point, client_id)) + .with_context(err_context)?; }, Action::MouseHoldMiddle(point) => { session .senders - .send_to_screen(ScreenInstruction::MouseHoldMiddle(point, client_id))?; + .send_to_screen(ScreenInstruction::MouseHoldMiddle(point, client_id)) + .with_context(err_context)?; }, Action::Copy => { session .senders - .send_to_screen(ScreenInstruction::Copy(client_id))?; + .send_to_screen(ScreenInstruction::Copy(client_id)) + .with_context(err_context)?; }, Action::Confirm => { session .senders - .send_to_screen(ScreenInstruction::ConfirmPrompt(client_id))?; + .send_to_screen(ScreenInstruction::ConfirmPrompt(client_id)) + .with_context(err_context)?; }, Action::Deny => { session .senders - .send_to_screen(ScreenInstruction::DenyPrompt(client_id))?; + .send_to_screen(ScreenInstruction::DenyPrompt(client_id)) + .with_context(err_context)?; }, #[allow(clippy::single_match)] Action::SkipConfirm(action) => match *action { Action::Quit => { - to_server.send(ServerInstruction::ClientExit(client_id))?; + to_server + .send(ServerInstruction::ClientExit(client_id)) + .with_context(err_context)?; should_break = true; }, _ => {}, @@ -483,14 +561,15 @@ pub(crate) fn route_action( Action::SearchInput(c) => { session .senders - .send_to_screen(ScreenInstruction::UpdateSearch(c, client_id))?; + .send_to_screen(ScreenInstruction::UpdateSearch(c, client_id)) + .with_context(err_context)?; }, Action::Search(d) => { let instruction = match d { SearchDirection::Down => ScreenInstruction::SearchDown(client_id), SearchDirection::Up => ScreenInstruction::SearchUp(client_id), }; - session.senders.send_to_screen(instruction)?; + session.senders.send_to_screen(instruction).with_context(err_context)?; }, Action::SearchToggleOption(o) => { let instruction = match o { @@ -500,7 +579,7 @@ pub(crate) fn route_action( SearchOption::WholeWord => ScreenInstruction::SearchToggleWholeWord(client_id), SearchOption::Wrap => ScreenInstruction::SearchToggleWrap(client_id), }; - session.senders.send_to_screen(instruction)?; + session.senders.send_to_screen(instruction).with_context(err_context)?; }, } Ok(should_break) @@ -532,6 +611,7 @@ pub(crate) fn route_thread_main( client_id: ClientId, ) -> Result<()> { let mut retry_queue = vec![]; + let err_context = ||format!("failed to handle instruction for client {client_id}"); 'route_loop: loop { match receiver.recv() { Some((instruction, err_ctx)) => { @@ -635,12 +715,12 @@ pub(crate) fn route_thread_main( client_id, plugin_config, ); - to_server.send(new_client_instruction).unwrap(); + to_server.send(new_client_instruction).with_context(err_context)?; }, ClientToServerMsg::AttachClient(client_attributes, opts) => { let attach_client_instruction = ServerInstruction::AttachClient(client_attributes, opts, client_id); - to_server.send(attach_client_instruction).unwrap(); + to_server.send(attach_client_instruction).with_context(err_context)?; }, ClientToServerMsg::ClientExited => { // we don't unwrap this because we don't really care if there's an error here (eg. @@ -649,7 +729,7 @@ pub(crate) fn route_thread_main( return Ok(true); }, ClientToServerMsg::KillSession => { - to_server.send(ServerInstruction::KillSession).unwrap(); + to_server.send(ServerInstruction::KillSession).with_context(err_context)?; }, ClientToServerMsg::ConnStatus => { let _ = to_server.send(ServerInstruction::ConnStatus(client_id)); From 070244f9efc21e3acd62b862160e6cc15fb64aae Mon Sep 17 00:00:00 2001 From: pingao Date: Fri, 21 Oct 2022 10:35:35 +0800 Subject: [PATCH 4/5] format code --- zellij-server/src/lib.rs | 3 +- zellij-server/src/route.rs | 64 +++++++++++++++++++++++++++++--------- 2 files changed, 52 insertions(+), 15 deletions(-) diff --git a/zellij-server/src/lib.rs b/zellij-server/src/lib.rs index fa871f7311..e2641f6cf9 100644 --- a/zellij-server/src/lib.rs +++ b/zellij-server/src/lib.rs @@ -275,7 +275,8 @@ pub fn start_server(mut os_input: Box, socket_path: PathBuf) { to_server, receiver, client_id, - ).fatal() + ) + .fatal() }) .unwrap(), ); diff --git a/zellij-server/src/route.rs b/zellij-server/src/route.rs index ad2714a609..87c584ddb0 100644 --- a/zellij-server/src/route.rs +++ b/zellij-server/src/route.rs @@ -111,7 +111,10 @@ pub(crate) fn route_action( ResizeDirection::Increase => ScreenInstruction::ResizeIncrease(client_id), ResizeDirection::Decrease => ScreenInstruction::ResizeDecrease(client_id), }; - session.senders.send_to_screen(screen_instr).with_context(err_context)?; + session + .senders + .send_to_screen(screen_instr) + .with_context(err_context)?; }, Action::SwitchFocus => { session @@ -138,7 +141,10 @@ pub(crate) fn route_action( Direction::Up => ScreenInstruction::MoveFocusUp(client_id), Direction::Down => ScreenInstruction::MoveFocusDown(client_id), }; - session.senders.send_to_screen(screen_instr).with_context(err_context)?; + session + .senders + .send_to_screen(screen_instr) + .with_context(err_context)?; }, Action::MoveFocusOrTab(direction) => { let screen_instr = match direction { @@ -147,7 +153,10 @@ pub(crate) fn route_action( Direction::Up => ScreenInstruction::SwitchTabNext(client_id), Direction::Down => ScreenInstruction::SwitchTabPrev(client_id), }; - session.senders.send_to_screen(screen_instr).with_context(err_context)?; + session + .senders + .send_to_screen(screen_instr) + .with_context(err_context)?; }, Action::MovePane(direction) => { let screen_instr = match direction { @@ -157,7 +166,10 @@ pub(crate) fn route_action( Some(Direction::Down) => ScreenInstruction::MovePaneDown(client_id), None => ScreenInstruction::MovePane(client_id), }; - session.senders.send_to_screen(screen_instr).with_context(err_context)?; + session + .senders + .send_to_screen(screen_instr) + .with_context(err_context)?; }, Action::DumpScreen(val, full) => { session @@ -260,7 +272,10 @@ pub(crate) fn route_action( ClientOrTabIndex::ClientId(client_id), ), }; - session.senders.send_to_pty(pty_instr).with_context(err_context)?; + session + .senders + .send_to_pty(pty_instr) + .with_context(err_context)?; }, Action::EditFile(path_to_file, line_number, split_direction, should_float) => { let title = format!("Editing: {}", path_to_file.display()); @@ -290,7 +305,10 @@ pub(crate) fn route_action( ClientOrTabIndex::ClientId(client_id), ), }; - session.senders.send_to_pty(pty_instr).with_context(err_context)?; + session + .senders + .send_to_pty(pty_instr) + .with_context(err_context)?; }, Action::SwitchModeForAllClients(input_mode) => { let attrs = &session.client_attributes; @@ -352,7 +370,10 @@ pub(crate) fn route_action( ClientOrTabIndex::ClientId(client_id), ), }; - session.senders.send_to_pty(pty_instr).with_context(err_context)?; + session + .senders + .send_to_pty(pty_instr) + .with_context(err_context)?; }, Action::TogglePaneEmbedOrFloating => { session @@ -404,7 +425,10 @@ pub(crate) fn route_action( ClientOrTabIndex::ClientId(client_id), ), }; - session.senders.send_to_pty(pty_instr).with_context(err_context)?; + session + .senders + .send_to_pty(pty_instr) + .with_context(err_context)?; }, Action::CloseFocus => { session @@ -569,7 +593,10 @@ pub(crate) fn route_action( SearchDirection::Down => ScreenInstruction::SearchDown(client_id), SearchDirection::Up => ScreenInstruction::SearchUp(client_id), }; - session.senders.send_to_screen(instruction).with_context(err_context)?; + session + .senders + .send_to_screen(instruction) + .with_context(err_context)?; }, Action::SearchToggleOption(o) => { let instruction = match o { @@ -579,7 +606,10 @@ pub(crate) fn route_action( SearchOption::WholeWord => ScreenInstruction::SearchToggleWholeWord(client_id), SearchOption::Wrap => ScreenInstruction::SearchToggleWrap(client_id), }; - session.senders.send_to_screen(instruction).with_context(err_context)?; + session + .senders + .send_to_screen(instruction) + .with_context(err_context)?; }, } Ok(should_break) @@ -611,7 +641,7 @@ pub(crate) fn route_thread_main( client_id: ClientId, ) -> Result<()> { let mut retry_queue = vec![]; - let err_context = ||format!("failed to handle instruction for client {client_id}"); + let err_context = || format!("failed to handle instruction for client {client_id}"); 'route_loop: loop { match receiver.recv() { Some((instruction, err_ctx)) => { @@ -715,12 +745,16 @@ pub(crate) fn route_thread_main( client_id, plugin_config, ); - to_server.send(new_client_instruction).with_context(err_context)?; + to_server + .send(new_client_instruction) + .with_context(err_context)?; }, ClientToServerMsg::AttachClient(client_attributes, opts) => { let attach_client_instruction = ServerInstruction::AttachClient(client_attributes, opts, client_id); - to_server.send(attach_client_instruction).with_context(err_context)?; + to_server + .send(attach_client_instruction) + .with_context(err_context)?; }, ClientToServerMsg::ClientExited => { // we don't unwrap this because we don't really care if there's an error here (eg. @@ -729,7 +763,9 @@ pub(crate) fn route_thread_main( return Ok(true); }, ClientToServerMsg::KillSession => { - to_server.send(ServerInstruction::KillSession).with_context(err_context)?; + to_server + .send(ServerInstruction::KillSession) + .with_context(err_context)?; }, ClientToServerMsg::ConnStatus => { let _ = to_server.send(ServerInstruction::ConnStatus(client_id)); From 86510a3a49a721edea55803feccfa91add5e1b35 Mon Sep 17 00:00:00 2001 From: pingao Date: Fri, 21 Oct 2022 11:07:06 +0800 Subject: [PATCH 5/5] improve error handling in route --- zellij-server/src/route.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/zellij-server/src/route.rs b/zellij-server/src/route.rs index 87c584ddb0..015b001088 100644 --- a/zellij-server/src/route.rs +++ b/zellij-server/src/route.rs @@ -686,13 +686,13 @@ pub(crate) fn route_thread_main( .read() .unwrap() .min_client_terminal_size() - .unwrap(); + .with_context(err_context)?; rlocked_sessions .as_ref() .unwrap() .senders .send_to_screen(ScreenInstruction::TerminalResize(min_size)) - .unwrap(); + .with_context(err_context)?; }, ClientToServerMsg::TerminalPixelDimensions(pixel_dimensions) => { send_to_screen_or_retry_queue!(