diff options
| author | har7an <99636919+har7an@users.noreply.github.com> | 2022-11-08 10:56:23 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-11-08 10:56:23 +0000 |
| commit | 453142775c96752730d7caf85532e616e2aaa719 (patch) | |
| tree | 607aff5d44ec5894fa98b7e4d108f8bb2815684c /zellij-server/src/os_input_output.rs | |
| parent | docs(changelog): various no-frame bugs (diff) | |
| download | sl0ppij-453142775c96752730d7caf85532e616e2aaa719.tar.gz sl0ppij-453142775c96752730d7caf85532e616e2aaa719.tar.xz sl0ppij-453142775c96752730d7caf85532e616e2aaa719.zip | |
errors: Remove `log::error` in server (#1881)
* server/wasm_vm: Replace `log::error!`
with better error logging by means of `non_fatal`. This preserves the
original error and allows adding context information on top. Also makes
error formatting more uniform across the application.
* server/tab: Replace `log::error!`
with better error logging by means of `non_fatal`. This preserves the
original error and allows adding context information on top. Also makes
error formatting more uniform across the application.
* server/route: Replace `log::error!`
and propagate the error to the caller instead.
* server/pty: Replace `log::error!`
with better error logging by means of `non_fatal`. This preserves the
original error and allows adding context information on top. Also makes
error formatting more uniform across the application.
Also add per-instruction error context to make it clear what we tried to
accomplish when an error occured.
* server/panes/tiled_panes: Merge dependencies
and sort them into a better order.
* server/panes/tiled_panes: Replace `log::error!`
with better error logging by means of `non_fatal`. This preserves the
original error and allows adding context information on top. Also makes
error formatting more uniform across the application.
* server/os_input_output: Merge depndencies
and sort them into a better order.
* server/logging_pipe: Replace `log::error!`
with better error logging by means of `non_fatal`. This preserves the
original error and allows adding context information on top. Also makes
error formatting more uniform across the application.
* server/os_io: Remove uses of `log::error`
* changelog: Add PR #1881
* server/os_io: Gracefully handle failing resize
for terminals IDs that don't exist, instead of propagating the error to
the user.
* server/lib: Remove leftover log message
* server/pty: Log error cause
rather than providing a hard-coded error reason which is plain wrong in
this context.
* server/screen: Remove calls to `log::error!`
and change `get_active_tab(_mut)?` to return a `Result` instead of an
`Option`. This already makes many places in the code obsolete where
previously "failed to get active tab..." was logged manually.
Rather than logging, use the `anyhow::Error`s we have, along with all
their context information, and log these instead.
Diffstat (limited to 'zellij-server/src/os_input_output.rs')
| -rw-r--r-- | zellij-server/src/os_input_output.rs | 82 |
1 files changed, 43 insertions, 39 deletions
diff --git a/zellij-server/src/os_input_output.rs b/zellij-server/src/os_input_output.rs index 322cfb9f..24a2ace2 100644 --- a/zellij-server/src/os_input_output.rs +++ b/zellij-server/src/os_input_output.rs @@ -1,45 +1,44 @@ -use std::collections::{BTreeMap, HashMap, HashSet}; -use std::{fs::File, io::Write}; +use crate::{panes::PaneId, ClientId}; -use crate::panes::PaneId; -use zellij_utils::tempfile::tempfile; - -use std::env; -use std::os::unix::io::RawFd; -use std::os::unix::process::CommandExt; -use std::path::PathBuf; -use std::process::{Child, Command}; -use std::sync::{Arc, Mutex}; - -use zellij_utils::errors::prelude::*; -use zellij_utils::{async_std, interprocess, libc, nix, signal_hook}; - -use async_std::fs::File as AsyncFile; -use async_std::os::unix::io::FromRawFd; +use async_std::{fs::File as AsyncFile, io::ReadExt, os::unix::io::FromRawFd}; use interprocess::local_socket::LocalSocketStream; - -use sysinfo::{ProcessExt, ProcessRefreshKind, System, SystemExt}; - -use nix::pty::{openpty, OpenptyResult, Winsize}; -use nix::sys::signal::{kill, Signal}; -use nix::sys::termios; - -use nix::unistd; +use nix::{ + pty::{openpty, OpenptyResult, Winsize}, + sys::{ + signal::{kill, Signal}, + termios, + }, + unistd, +}; use signal_hook::consts::*; +use sysinfo::{ProcessExt, ProcessRefreshKind, System, SystemExt}; use zellij_utils::{ + async_std, data::Palette, + errors::prelude::*, input::command::{RunCommand, TerminalAction}, + interprocess, ipc::{ClientToServerMsg, IpcReceiverWithContext, IpcSenderWithContext, ServerToClientMsg}, + libc, nix, shared::default_palette, + signal_hook, + tempfile::tempfile, }; -use async_std::io::ReadExt; -pub use async_trait::async_trait; +use std::{ + collections::{BTreeMap, HashMap, HashSet}, + env, + fs::File, + io::Write, + os::unix::{io::RawFd, process::CommandExt}, + path::PathBuf, + process::{Child, Command}, + sync::{Arc, Mutex}, +}; +pub use async_trait::async_trait; pub use nix::unistd::Pid; -use crate::ClientId; - fn set_terminal_size_using_fd(fd: RawFd, columns: u16, rows: u16) { // TODO: do this with the nix ioctl use libc::ioctl; @@ -164,10 +163,11 @@ fn handle_openpty( command.current_dir(current_dir); } else { // TODO: propagate this to the user - log::error!( - "Failed to set CWD for new pane. {} does not exist or is not a folder", + return Err(anyhow!( + "Failed to set CWD for new pane. '{}' does not exist or is not a folder", current_dir.display() - ); + )) + .context("failed to open PTY"); } } command @@ -417,16 +417,18 @@ pub trait ServerOsApi: Send + Sync { impl ServerOsApi for ServerOsInputOutput { fn set_terminal_size_using_terminal_id(&self, id: u32, cols: u16, rows: u16) -> Result<()> { + let err_context = || { + format!( + "failed to set terminal id {} to size ({}, {})", + id, rows, cols + ) + }; + match self .terminal_id_to_raw_fd .lock() .to_anyhow() - .with_context(|| { - format!( - "failed to set terminal id {} to size ({}, {})", - id, rows, cols - ) - })? + .with_context(err_context)? .get(&id) { Some(Some(fd)) => { @@ -435,7 +437,9 @@ impl ServerOsApi for ServerOsInputOutput { } }, _ => { - log::error!("Failed to find terminal fd for id: {id}, so cannot resize terminal"); + Err::<(), _>(anyhow!("failed to find terminal fd for id {id}")) + .with_context(err_context) + .non_fatal(); }, } Ok(()) |
