Skip to main content

soma_mcp_client/process/
stderr.rs

1use std::io::{self, Read};
2
3#[derive(Debug, Clone, PartialEq, Eq)]
4pub struct DrainedStderr {
5    pub text: String,
6    pub truncated: bool,
7}
8
9pub fn drain_stderr_with_cap<R: Read>(
10    mut reader: R,
11    cap_bytes: usize,
12) -> io::Result<DrainedStderr> {
13    let mut buf = Vec::new();
14    reader.read_to_end(&mut buf)?;
15    let truncated = buf.len() > cap_bytes;
16    if truncated {
17        buf.truncate(cap_bytes);
18    }
19    Ok(DrainedStderr {
20        text: String::from_utf8_lossy(&buf).into_owned(),
21        truncated,
22    })
23}
24
25#[cfg(test)]
26#[path = "stderr_tests.rs"]
27mod tests;