mirror of
https://github.com/ClementTsang/bottom
synced 2024-11-21 19:53:05 +00:00
refactor: convert more errors over (#1496)
* refactor: remove From<String> for BottomError * fix kill_process
This commit is contained in:
parent
1ec4ca3f06
commit
c56e28328e
3 changed files with 15 additions and 17 deletions
|
@ -10,7 +10,6 @@ use windows::Win32::{
|
|||
};
|
||||
|
||||
use crate::data_collection::processes::Pid;
|
||||
#[cfg(target_family = "unix")]
|
||||
use crate::utils::error::BottomError;
|
||||
|
||||
/// Based from [this SO answer](https://stackoverflow.com/a/55231715).
|
||||
|
@ -51,10 +50,8 @@ impl Drop for Process {
|
|||
/// Kills a process, given a PID, for windows.
|
||||
#[cfg(target_os = "windows")]
|
||||
pub fn kill_process_given_pid(pid: Pid) -> crate::utils::error::Result<()> {
|
||||
{
|
||||
let process = Process::open(pid as u32)?;
|
||||
process.kill()?;
|
||||
}
|
||||
let process = Process::open(pid as u32).map_err(BottomError::GenericError)?;
|
||||
process.kill().map_err(BottomError::GenericError)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -64,8 +61,8 @@ pub fn kill_process_given_pid(pid: Pid) -> crate::utils::error::Result<()> {
|
|||
pub fn kill_process_given_pid(pid: Pid, signal: usize) -> crate::utils::error::Result<()> {
|
||||
// SAFETY: the signal should be valid, and we act properly on an error (exit
|
||||
// code not 0).
|
||||
|
||||
let output = unsafe { libc::kill(pid, signal as i32) };
|
||||
|
||||
if output != 0 {
|
||||
// We had an error...
|
||||
let err_code = std::io::Error::last_os_error().raw_os_error();
|
||||
|
|
|
@ -8,7 +8,6 @@ pub use crate::options::ConfigV1;
|
|||
use crate::{
|
||||
constants::*,
|
||||
options::{colours::ColoursConfig, OptionError, OptionResult},
|
||||
utils::error,
|
||||
};
|
||||
|
||||
pub struct CanvasStyling {
|
||||
|
@ -206,18 +205,26 @@ impl CanvasStyling {
|
|||
|
||||
if let Some(scroll_entry_text_color) = &colours.selected_text_color {
|
||||
self.set_scroll_entry_text_color(scroll_entry_text_color)
|
||||
.map_err(|_| OptionError::invalid_config_value("selected_text_color"))?
|
||||
.map_err(|err| {
|
||||
OptionError::config(format!(
|
||||
"Please update 'colors.selected_text_color' in your config file. {err}",
|
||||
))
|
||||
})?
|
||||
}
|
||||
|
||||
if let Some(scroll_entry_bg_color) = &colours.selected_bg_color {
|
||||
self.set_scroll_entry_bg_color(scroll_entry_bg_color)
|
||||
.map_err(|_| OptionError::invalid_config_value("selected_bg_color"))?
|
||||
.map_err(|err| {
|
||||
OptionError::config(format!(
|
||||
"Please update 'colors.selected_bg_color' in your config file. {err}",
|
||||
))
|
||||
})?
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn set_scroll_entry_text_color(&mut self, colour: &str) -> error::Result<()> {
|
||||
fn set_scroll_entry_text_color(&mut self, colour: &str) -> Result<(), String> {
|
||||
self.currently_selected_text_colour = str_to_colour(colour)?;
|
||||
self.currently_selected_text_style = Style::default()
|
||||
.fg(self.currently_selected_text_colour)
|
||||
|
@ -226,7 +233,7 @@ impl CanvasStyling {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn set_scroll_entry_bg_color(&mut self, colour: &str) -> error::Result<()> {
|
||||
fn set_scroll_entry_bg_color(&mut self, colour: &str) -> Result<(), String> {
|
||||
self.currently_selected_bg_colour = str_to_colour(colour)?;
|
||||
self.currently_selected_text_style = Style::default()
|
||||
.fg(self.currently_selected_text_colour)
|
||||
|
|
|
@ -21,9 +21,3 @@ impl From<std::io::Error> for BottomError {
|
|||
BottomError::InvalidIo(err.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<String> for BottomError {
|
||||
fn from(err: String) -> Self {
|
||||
BottomError::GenericError(err)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue