diff options
author | har7an <99636919+har7an@users.noreply.github.com> | 2022-09-09 13:21:03 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-09 13:21:03 +0000 |
commit | 99e2bef8c68bd166cf89e90c8ffe8c02272ab4d3 (patch) | |
tree | 1eb34d081e8d96c9f6d49f26beb8e0d97666aa6e /zellij-server/src/unit/screen_tests.rs | |
parent | 3f43a057cb65e5790f8024fe0d961255f6699678 (diff) |
Feature: Better error handling/reporting (#1670)
* utils: re-export "anyhow" unconditionally
even for wasm targets.
* utils/errors: Share wasm-compatible code
and move everything that can't run in wasm into a separate submodule.
* utils: Share "errors" module unconditionally
The module is now structured such that all code incompatible with wasm
targets lives in its own submodule that isn't included when compiling
for wasm targets.
* utils/errors: Add "Help wanted" doc section
that informs the reader about the endeavour to improve error handling
throughout the zellij code base.
* plugins: Handle errors returned by `zellij_tile`
now that the panic calls have been removed.
* utils/errors: Extend `anyhow::Result` with traits
that allow for easy/concise logging of `anyhow::Result` types and
panicking the application when they are fatal or non-fatal.
* utils/errors: Fix doctest
* utils/errors: Add prelude
that applications can import to conveniently access the error handling
functionality part of the module. Re-exports some parts and macros from
anyhow and the `LoggableError` and `FatalError` traits.
* server/screen: Adopt error handling
and make all fallible functions from the public API return a `Result`.
Append error contexts in all functions that can come across error types
to allow tracing where an error originates and what lead there.
* server/lib: Catch errors from `screen`
and make them `fatal`. This will log the errors first, before unwrapping
on the error type and panicking the application.
* server/unit/screen: Fix unit tests
and unwrap on the `Result` types introduced from the new error handling.
* utils/errors: Track error source
in calls to `fatal`, so we keep track of the location where the panic
really originates. Otherwise, any call to `fatal` will show the code in
`errors` as source, which of course isn't true.
Also change the error formatting and do not call `to_log` for fatal
errors anymore, because the panic is already logged and contains much
more information.
* utils/errors: Update `FatalError` docs
* plugins: Undo accidental modifications
* utils/errors: Improve module docs
explain some error handling facilities and the motivation behind using
them.
* server/screen: Remove `Result` from Infallible
functions that are part of the public API.
Diffstat (limited to 'zellij-server/src/unit/screen_tests.rs')
-rw-r--r-- | zellij-server/src/unit/screen_tests.rs | 66 |
1 files changed, 34 insertions, 32 deletions
diff --git a/zellij-server/src/unit/screen_tests.rs b/zellij-server/src/unit/screen_tests.rs index 53cb62d1c..28aec39cb 100644 --- a/zellij-server/src/unit/screen_tests.rs +++ b/zellij-server/src/unit/screen_tests.rs @@ -114,11 +114,13 @@ fn create_new_screen(size: Size) -> Screen { fn new_tab(screen: &mut Screen, pid: i32) { let client_id = 1; - screen.new_tab( - LayoutTemplate::default().try_into().unwrap(), - vec![pid], - client_id, - ); + screen + .new_tab( + LayoutTemplate::default().try_into().unwrap(), + vec![pid], + client_id, + ) + .expect("TEST"); } #[test] @@ -150,7 +152,7 @@ pub fn switch_to_prev_tab() { new_tab(&mut screen, 1); new_tab(&mut screen, 2); - screen.switch_tab_prev(1); + screen.switch_tab_prev(1).expect("TEST"); assert_eq!( screen.get_active_tab(1).unwrap().position, @@ -169,8 +171,8 @@ pub fn switch_to_next_tab() { new_tab(&mut screen, 1); new_tab(&mut screen, 2); - screen.switch_tab_prev(1); - screen.switch_tab_next(1); + screen.switch_tab_prev(1).expect("TEST"); + screen.switch_tab_next(1).expect("TEST"); assert_eq!( screen.get_active_tab(1).unwrap().position, @@ -189,7 +191,7 @@ pub fn close_tab() { new_tab(&mut screen, 1); new_tab(&mut screen, 2); - screen.close_tab(1); + screen.close_tab(1).expect("TEST"); assert_eq!(screen.tabs.len(), 1, "Only one tab left"); assert_eq!( @@ -210,8 +212,8 @@ pub fn close_the_middle_tab() { new_tab(&mut screen, 1); new_tab(&mut screen, 2); new_tab(&mut screen, 3); - screen.switch_tab_prev(1); - screen.close_tab(1); + screen.switch_tab_prev(1).expect("TEST"); + screen.close_tab(1).expect("TEST"); assert_eq!(screen.tabs.len(), 2, "Two tabs left"); assert_eq!( @@ -232,8 +234,8 @@ fn move_focus_left_at_left_screen_edge_changes_tab() { new_tab(&mut screen, 1); new_tab(&mut screen, 2); new_tab(&mut screen, 3); - screen.switch_tab_prev(1); - screen.move_focus_left_or_previous_tab(1); + screen.switch_tab_prev(1).expect("TEST"); + screen.move_focus_left_or_previous_tab(1).expect("TEST"); assert_eq!( screen.get_active_tab(1).unwrap().position, @@ -253,8 +255,8 @@ fn move_focus_right_at_right_screen_edge_changes_tab() { new_tab(&mut screen, 1); new_tab(&mut screen, 2); new_tab(&mut screen, 3); - screen.switch_tab_prev(1); - screen.move_focus_right_or_next_tab(1); + screen.switch_tab_prev(1).expect("TEST"); + screen.move_focus_right_or_next_tab(1).expect("TEST"); assert_eq!( screen.get_active_tab(1).unwrap().position, @@ -273,17 +275,17 @@ pub fn toggle_to_previous_tab_simple() { new_tab(&mut screen, 1); new_tab(&mut screen, 2); - screen.go_to_tab(1, 1); - screen.go_to_tab(2, 1); + screen.go_to_tab(1, 1).expect("TEST"); + screen.go_to_tab(2, 1).expect("TEST"); - screen.toggle_tab(1); + screen.toggle_tab(1).expect("TEST"); assert_eq!( screen.get_active_tab(1).unwrap().position, 0, "Active tab toggler to previous tab" ); - screen.toggle_tab(1); + screen.toggle_tab(1).expect("TEST"); assert_eq!( screen.get_active_tab(1).unwrap().position, 1, @@ -309,7 +311,7 @@ pub fn toggle_to_previous_tab_create_tabs_only() { "Tab history is invalid" ); - screen.toggle_tab(1); + screen.toggle_tab(1).expect("TEST"); assert_eq!( screen.get_active_tab(1).unwrap().position, 1, @@ -321,7 +323,7 @@ pub fn toggle_to_previous_tab_create_tabs_only() { "Tab history is invalid" ); - screen.toggle_tab(1); + screen.toggle_tab(1).expect("TEST"); assert_eq!( screen.get_active_tab(1).unwrap().position, 2, @@ -333,7 +335,7 @@ pub fn toggle_to_previous_tab_create_tabs_only() { "Tab history is invalid" ); - screen.toggle_tab(1); + screen.toggle_tab(1).expect("TEST"); assert_eq!( screen.get_active_tab(1).unwrap().position, 1, @@ -365,7 +367,7 @@ pub fn toggle_to_previous_tab_delete() { "Active tab toggler to previous tab" ); - screen.toggle_tab(1); + screen.toggle_tab(1).expect("TEST"); assert_eq!( screen.tab_history.get(&1).unwrap(), &[0, 1, 3], @@ -377,7 +379,7 @@ pub fn toggle_to_previous_tab_delete() { "Active tab toggler to previous tab" ); - screen.toggle_tab(1); + screen.toggle_tab(1).expect("TEST"); assert_eq!( screen.tab_history.get(&1).unwrap(), &[0, 1, 2], @@ -389,7 +391,7 @@ pub fn toggle_to_previous_tab_delete() { "Active tab toggler to previous tab" ); - screen.switch_tab_prev(1); + screen.switch_tab_prev(1).expect("TEST"); assert_eq!( screen.tab_history.get(&1).unwrap(), &[0, 1, 3], @@ -400,7 +402,7 @@ pub fn toggle_to_previous_tab_delete() { 2, "Active tab toggler to previous tab" ); - screen.switch_tab_prev(1); + screen.switch_tab_prev(1).expect("TEST"); assert_eq!( screen.tab_history.get(&1).unwrap(), &[0, 3, 2], @@ -412,7 +414,7 @@ pub fn toggle_to_previous_tab_delete() { "Active tab toggler to previous tab" ); - screen.close_tab(1); + screen.close_tab(1).expect("TEST"); assert_eq!( screen.tab_history.get(&1).unwrap(), &[0, 3], @@ -424,7 +426,7 @@ pub fn toggle_to_previous_tab_delete() { "Active tab toggler to previous tab" ); - screen.toggle_tab(1); + screen.toggle_tab(1).expect("TEST"); assert_eq!( screen.get_active_tab(1).unwrap().position, 2, @@ -453,7 +455,7 @@ fn switch_to_tab_with_fullscreen() { } new_tab(&mut screen, 2); - screen.switch_tab_prev(1); + screen.switch_tab_prev(1).expect("TEST"); assert_eq!( screen.get_active_tab(1).unwrap().position, @@ -566,7 +568,7 @@ fn attach_after_first_tab_closed() { } new_tab(&mut screen, 2); - screen.close_tab_at_index(0); - screen.remove_client(1); - screen.add_client(1); + screen.close_tab_at_index(0).expect("TEST"); + screen.remove_client(1).expect("TEST"); + screen.add_client(1).expect("TEST"); } |