aboutsummaryrefslogtreecommitdiffstats
path: root/zellij-server/src/logging_pipe.rs
diff options
context:
space:
mode:
authorhar7an <99636919+har7an@users.noreply.github.com>2022-11-08 10:56:23 +0000
committerGitHub <noreply@github.com>2022-11-08 10:56:23 +0000
commit453142775c96752730d7caf85532e616e2aaa719 (patch)
tree607aff5d44ec5894fa98b7e4d108f8bb2815684c /zellij-server/src/logging_pipe.rs
parentdocs(changelog): various no-frame bugs (diff)
downloadsl0ppij-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/logging_pipe.rs')
-rw-r--r--zellij-server/src/logging_pipe.rs35
1 files changed, 19 insertions, 16 deletions
diff --git a/zellij-server/src/logging_pipe.rs b/zellij-server/src/logging_pipe.rs
index 085a672f..d54de9b0 100644
--- a/zellij-server/src/logging_pipe.rs
+++ b/zellij-server/src/logging_pipe.rs
@@ -5,7 +5,7 @@ use std::{
use log::{debug, error};
use wasmer_wasi::{WasiFile, WasiFsError};
-use zellij_utils::serde;
+use zellij_utils::{errors::prelude::*, serde};
use chrono::prelude::*;
use serde::{Deserialize, Serialize};
@@ -75,27 +75,30 @@ impl Write for LoggingPipe {
fn flush(&mut self) -> std::io::Result<()> {
self.buffer.make_contiguous();
- if let Ok(converted_buffer) = std::str::from_utf8(self.buffer.as_slices().0) {
- if converted_buffer.contains('\n') {
- let mut consumed_bytes = 0;
- let mut split_converted_buffer = converted_buffer.split('\n').peekable();
+ match std::str::from_utf8(self.buffer.as_slices().0) {
+ Ok(converted_buffer) => {
+ if converted_buffer.contains('\n') {
+ let mut consumed_bytes = 0;
+ let mut split_converted_buffer = converted_buffer.split('\n').peekable();
- while let Some(msg) = split_converted_buffer.next() {
- if split_converted_buffer.peek().is_none() {
- // Log last chunk iff the last char is endline. Otherwise do not do it.
- if converted_buffer.ends_with('\n') && !msg.is_empty() {
+ while let Some(msg) = split_converted_buffer.next() {
+ if split_converted_buffer.peek().is_none() {
+ // Log last chunk iff the last char is endline. Otherwise do not do it.
+ if converted_buffer.ends_with('\n') && !msg.is_empty() {
+ self.log_message(msg);
+ consumed_bytes += msg.len() + 1;
+ }
+ } else {
self.log_message(msg);
consumed_bytes += msg.len() + 1;
}
- } else {
- self.log_message(msg);
- consumed_bytes += msg.len() + 1;
}
+ drop(self.buffer.drain(..consumed_bytes));
}
- drop(self.buffer.drain(..consumed_bytes));
- }
- } else {
- error!("Buffer conversion didn't work. This is unexpected");
+ },
+ Err(e) => Err::<(), _>(e)
+ .context("failed to flush logging pipe buffer")
+ .non_fatal(),
}
Ok(())