diff options
author | har7an <99636919+har7an@users.noreply.github.com> | 2022-11-02 05:29:50 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-02 05:29:50 +0000 |
commit | e45a3e58267925b710a5612b4d01b175c2962bcf (patch) | |
tree | 213d9012b71001c3b1358e85ad6f9bb03b07094b /zellij-server/src/panes | |
parent | 373351a26578bff1d1a3656a48b5656600f2bb43 (diff) |
errors: Don't unwrap in `server::os_input_output` (#1895)
* server/os_io: Redefine `ServerOsApi` result types
to use `anyhow::Result` instead. This mostly makes the need of custom
`SpawnTerminalError` obsolete (tbd in subsequent commits) and unifies
error handling across the application.
* utils/errors: Implement new `ZellijError` type
to replace any previously defined, isolated custom error types
throughout the application. Currently implements all error variants
found in `SpawnTerminalError`.
In the long term, this will allow zellij to fall back to a single error
type for all application-specific errors, instead of having different
error types per module.
* server/unit/screen: Impl new `ServerOsApi`
with updated `Result`-types.
* server/tab/unit: Impl new `ServerOsApi`
with updated `Result`-types.
* server/os_io: Impl new `ServerOsApi`
with updated `Result`-types.
* utils/ipc: Return `anyhow::Error` in `send`
rather than a `&'static str`, which isn't compatible with
`anyhow::Context`.
* server/tab: Handle `Result` in `resize_pty!`
which is returned due to the changed return types in `ServerOsApi`.
* server/tab: Handle new `Result`s
originating in the change to the `ServerOsApi` trait definition.
* server/screen: Handle new `Result`s
originating in the change to the `ServerOsApi` trait definition.
* server/panes/tiled: Handle new `Result`s
originating in the change to the `ServerOsApi` trait definition.
* server/panes/floating: Handle new `Result`s
originating in the change to the `ServerOsApi` trait definition.
* server/lib: Unwrap on new `Result`s
originating in the change to the `ServerOsApi` trait definition. The
functions here don't return a `Result` yet, this is better left to a
follow-up PR.
* server: Remove `SpawnTerminalError`
and make use of the new `ZellijError` instead. Make use of `anyhow`s
downcast capabilities to restore the underlying original errors where
necessary, as was done previously. This gives us the flexibility to
attach context information to all errors while still allowing us to
handle specific errors in greater detail.
* server/pty: Fix vars broken in rebase
* server/os_io: Remove last `SpawnTerminalError`
* changelog: Add PR #1895
Diffstat (limited to 'zellij-server/src/panes')
-rw-r--r-- | zellij-server/src/panes/floating_panes/mod.rs | 20 | ||||
-rw-r--r-- | zellij-server/src/panes/tiled_panes/mod.rs | 38 |
2 files changed, 31 insertions, 27 deletions
diff --git a/zellij-server/src/panes/floating_panes/mod.rs b/zellij-server/src/panes/floating_panes/mod.rs index d17be7557..48d4d700f 100644 --- a/zellij-server/src/panes/floating_panes/mod.rs +++ b/zellij-server/src/panes/floating_panes/mod.rs @@ -31,7 +31,9 @@ macro_rules! resize_pty { *pid, $pane.get_content_columns() as u16, $pane.get_content_rows() as u16, - ); + ) + } else { + Ok(()) } }; } @@ -233,7 +235,7 @@ impl FloatingPanes { } else { pane.set_content_offset(Offset::default()); } - resize_pty!(pane, os_api); + resize_pty!(pane, os_api).unwrap(); } } pub fn render(&mut self, output: &mut Output) -> Result<()> { @@ -313,7 +315,7 @@ impl FloatingPanes { } pub fn resize_pty_all_panes(&mut self, os_api: &mut Box<dyn ServerOsApi>) { for pane in self.panes.values_mut() { - resize_pty!(pane, os_api); + resize_pty!(pane, os_api).unwrap(); } } pub fn resize_active_pane_left( @@ -333,7 +335,7 @@ impl FloatingPanes { ); floating_pane_grid.resize_pane_left(active_floating_pane_id); for pane in self.panes.values_mut() { - resize_pty!(pane, os_api); + resize_pty!(pane, os_api).unwrap(); } self.set_force_render(); return true; @@ -357,7 +359,7 @@ impl FloatingPanes { ); floating_pane_grid.resize_pane_right(active_floating_pane_id); for pane in self.panes.values_mut() { - resize_pty!(pane, os_api); + resize_pty!(pane, os_api).unwrap(); } self.set_force_render(); return true; @@ -381,7 +383,7 @@ impl FloatingPanes { ); floating_pane_grid.resize_pane_down(active_floating_pane_id); for pane in self.panes.values_mut() { - resize_pty!(pane, os_api); + resize_pty!(pane, os_api).unwrap(); } self.set_force_render(); return true; @@ -405,7 +407,7 @@ impl FloatingPanes { ); floating_pane_grid.resize_pane_up(active_floating_pane_id); for pane in self.panes.values_mut() { - resize_pty!(pane, os_api); + resize_pty!(pane, os_api).unwrap(); } self.set_force_render(); return true; @@ -429,7 +431,7 @@ impl FloatingPanes { ); floating_pane_grid.resize_increase(active_floating_pane_id); for pane in self.panes.values_mut() { - resize_pty!(pane, os_api); + resize_pty!(pane, os_api).unwrap(); } self.set_force_render(); return true; @@ -453,7 +455,7 @@ impl FloatingPanes { ); floating_pane_grid.resize_decrease(active_floating_pane_id); for pane in self.panes.values_mut() { - resize_pty!(pane, os_api); + resize_pty!(pane, os_api).unwrap(); } self.set_force_render(); return true; diff --git a/zellij-server/src/panes/tiled_panes/mod.rs b/zellij-server/src/panes/tiled_panes/mod.rs index 7e7b7a1f9..86b21efde 100644 --- a/zellij-server/src/panes/tiled_panes/mod.rs +++ b/zellij-server/src/panes/tiled_panes/mod.rs @@ -29,7 +29,9 @@ macro_rules! resize_pty { *pid, $pane.get_content_columns() as u16, $pane.get_content_rows() as u16, - ); + ) + } else { + Ok(()) } }; } @@ -263,7 +265,7 @@ impl TiledPanes { pane.set_content_offset(Offset::shift(pane_rows_offset, pane_columns_offset)); } - resize_pty!(pane, self.os_api); + resize_pty!(pane, self.os_api).unwrap(); } } pub fn can_split_pane_horizontally(&mut self, client_id: ClientId) -> bool { @@ -507,7 +509,7 @@ impl TiledPanes { ); pane_grid.resize_pane_left(&active_pane_id); for pane in self.panes.values_mut() { - resize_pty!(pane, self.os_api); + resize_pty!(pane, self.os_api).unwrap(); } } } @@ -521,7 +523,7 @@ impl TiledPanes { ); pane_grid.resize_pane_right(&active_pane_id); for pane in self.panes.values_mut() { - resize_pty!(pane, self.os_api); + resize_pty!(pane, self.os_api).unwrap(); } } } @@ -535,7 +537,7 @@ impl TiledPanes { ); pane_grid.resize_pane_up(&active_pane_id); for pane in self.panes.values_mut() { - resize_pty!(pane, self.os_api); + resize_pty!(pane, self.os_api).unwrap(); } } } @@ -549,7 +551,7 @@ impl TiledPanes { ); pane_grid.resize_pane_down(&active_pane_id); for pane in self.panes.values_mut() { - resize_pty!(pane, self.os_api); + resize_pty!(pane, self.os_api).unwrap(); } } } @@ -563,7 +565,7 @@ impl TiledPanes { ); pane_grid.resize_increase(&active_pane_id); for pane in self.panes.values_mut() { - resize_pty!(pane, self.os_api); + resize_pty!(pane, self.os_api).unwrap(); } } } @@ -577,7 +579,7 @@ impl TiledPanes { ); pane_grid.resize_decrease(&active_pane_id); for pane in self.panes.values_mut() { - resize_pty!(pane, self.os_api); + resize_pty!(pane, self.os_api).unwrap(); } } } @@ -808,7 +810,7 @@ impl TiledPanes { if let Some(geom) = prev_geom_override { new_position.set_geom_override(geom); } - resize_pty!(new_position, self.os_api); + resize_pty!(new_position, self.os_api).unwrap(); new_position.set_should_render(true); let current_position = self.panes.get_mut(&active_pane_id).unwrap(); @@ -816,7 +818,7 @@ impl TiledPanes { if let Some(geom) = next_geom_override { current_position.set_geom_override(geom); } - resize_pty!(current_position, self.os_api); + resize_pty!(current_position, self.os_api).unwrap(); current_position.set_should_render(true); } pub fn move_active_pane_down(&mut self, client_id: ClientId) { @@ -841,7 +843,7 @@ impl TiledPanes { if let Some(geom) = prev_geom_override { new_position.set_geom_override(geom); } - resize_pty!(new_position, self.os_api); + resize_pty!(new_position, self.os_api).unwrap(); new_position.set_should_render(true); let current_position = self.panes.get_mut(active_pane_id).unwrap(); @@ -849,7 +851,7 @@ impl TiledPanes { if let Some(geom) = next_geom_override { current_position.set_geom_override(geom); } - resize_pty!(current_position, self.os_api); + resize_pty!(current_position, self.os_api).unwrap(); current_position.set_should_render(true); } } @@ -876,7 +878,7 @@ impl TiledPanes { if let Some(geom) = prev_geom_override { new_position.set_geom_override(geom); } - resize_pty!(new_position, self.os_api); + resize_pty!(new_position, self.os_api).unwrap(); new_position.set_should_render(true); let current_position = self.panes.get_mut(active_pane_id).unwrap(); @@ -884,7 +886,7 @@ impl TiledPanes { if let Some(geom) = next_geom_override { current_position.set_geom_override(geom); } - resize_pty!(current_position, self.os_api); + resize_pty!(current_position, self.os_api).unwrap(); current_position.set_should_render(true); } } @@ -911,7 +913,7 @@ impl TiledPanes { if let Some(geom) = prev_geom_override { new_position.set_geom_override(geom); } - resize_pty!(new_position, self.os_api); + resize_pty!(new_position, self.os_api).unwrap(); new_position.set_should_render(true); let current_position = self.panes.get_mut(active_pane_id).unwrap(); @@ -919,7 +921,7 @@ impl TiledPanes { if let Some(geom) = next_geom_override { current_position.set_geom_override(geom); } - resize_pty!(current_position, self.os_api); + resize_pty!(current_position, self.os_api).unwrap(); current_position.set_should_render(true); } } @@ -946,7 +948,7 @@ impl TiledPanes { if let Some(geom) = prev_geom_override { new_position.set_geom_override(geom); } - resize_pty!(new_position, self.os_api); + resize_pty!(new_position, self.os_api).unwrap(); new_position.set_should_render(true); let current_position = self.panes.get_mut(active_pane_id).unwrap(); @@ -954,7 +956,7 @@ impl TiledPanes { if let Some(geom) = next_geom_override { current_position.set_geom_override(geom); } - resize_pty!(current_position, self.os_api); + resize_pty!(current_position, self.os_api).unwrap(); current_position.set_should_render(true); } } |