This commit is contained in:
2025-04-02 07:49:15 +02:00
parent 5678a9aa35
commit 3606e27e30
6 changed files with 142 additions and 6 deletions

View File

@@ -4,16 +4,23 @@ use std::fmt;
use std::error::Error;
use std::io;
// Define a custom error type for process operations
/// Error type for process management operations
///
/// This enum represents various errors that can occur during process management
/// operations such as listing, finding, or killing processes.
#[derive(Debug)]
pub enum ProcessError {
/// An error occurred while executing a command
CommandExecutionFailed(io::Error),
/// A command executed successfully but returned an error
CommandFailed(String),
/// No process was found matching the specified pattern
NoProcessFound(String),
/// Multiple processes were found matching the specified pattern
MultipleProcessesFound(String, usize),
}
// Implement Display for ProcessError
/// Implement Display for ProcessError to provide human-readable error messages
impl fmt::Display for ProcessError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {

View File

@@ -1,2 +1,17 @@
//! # Process Module
//!
//! The `process` module provides functionality for managing and interacting with
//! system processes across different platforms. It includes capabilities for:
//!
//! - Running commands and scripts
//! - Listing and filtering processes
//! - Killing processes
//! - Checking for command existence
//!
//! This module is designed to work consistently across Windows, macOS, and Linux.
pub mod run;
pub mod mgmt;
use run::*;
use mgmt::*;

View File

@@ -7,23 +7,35 @@ use std::fmt;
use std::error::Error;
use std::io;
use super::text;
use crate::text;
// Define a custom error type for run operations
/// Error type for command and script execution operations
///
/// This enum represents various errors that can occur during command and script
/// execution, including preparation, execution, and output handling.
#[derive(Debug)]
pub enum RunError {
/// The command string was empty
EmptyCommand,
/// An error occurred while executing a command
CommandExecutionFailed(io::Error),
/// A command executed successfully but returned an error
CommandFailed(String),
/// An error occurred while preparing a script for execution
ScriptPreparationFailed(String),
/// An error occurred in a child process
ChildProcessError(String),
/// Failed to create a temporary directory
TempDirCreationFailed(io::Error),
/// Failed to create a script file
FileCreationFailed(io::Error),
/// Failed to write to a script file
FileWriteFailed(io::Error),
/// Failed to set file permissions
PermissionError(io::Error),
}
// Implement Display for RunError
/// Implement Display for RunError to provide human-readable error messages
impl fmt::Display for RunError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {