aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe-external-packages/src/symfony/process/exception/process_signaled_exception.rs
blob: 03c4df270e6b8e2e98a2b474bd74733cb25261e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
//! ref: composer/vendor/symfony/process/Exception/ProcessSignaledException.php

use crate::symfony::process::process::Process;

#[derive(Debug)]
pub struct ProcessSignaledException {
    pub message: String,
    pub code: i64,
    signal: i64,
}

impl ProcessSignaledException {
    pub fn new(process: &mut Process) -> anyhow::Result<Self> {
        let signal = process.get_term_signal()?;

        Ok(Self {
            message: format!("The process has been signaled with signal \"{}\".", signal),
            code: 0,
            signal,
        })
    }

    pub fn get_signal(&self) -> i64 {
        self.signal
    }
}

impl std::fmt::Display for ProcessSignaledException {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self.message)
    }
}

impl std::error::Error for ProcessSignaledException {}