isothrum_runner/error/
timed_out.rs1use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, schemars::JsonSchema)]
13#[serde(tag = "kind", rename_all = "snake_case")]
14#[non_exhaustive]
15pub enum TimedOut {
16 NoProgress {
18 after_s: u64,
20 #[serde(default, skip_serializing_if = "Option::is_none")]
23 last_line: Option<String>,
24 },
25 Ceiling {
27 after_s: u64,
29 },
30}
31
32impl TimedOut {
33 #[must_use]
35 pub fn after_s(&self) -> u64 {
36 match self {
37 TimedOut::NoProgress { after_s, .. } | TimedOut::Ceiling { after_s } => *after_s,
38 }
39 }
40
41 pub(crate) fn masked(self, mask: impl FnOnce(&str) -> String) -> TimedOut {
43 match self {
44 TimedOut::NoProgress { after_s, last_line } => TimedOut::NoProgress {
45 after_s,
46 last_line: last_line.map(|l| mask(&l)),
47 },
48 ceiling @ TimedOut::Ceiling { .. } => ceiling,
49 }
50 }
51}
52
53impl std::fmt::Display for TimedOut {
54 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
55 match self {
56 TimedOut::NoProgress {
57 after_s,
58 last_line: Some(line),
59 } => {
60 write!(f, "showed no progress for {after_s}s and was stopped; its last line: `{line}`")
61 }
62 TimedOut::NoProgress { after_s, last_line: None } => write!(f, "printed nothing for {after_s}s and was stopped"),
63 TimedOut::Ceiling { after_s } => {
64 write!(f, "was stopped after {after_s}s, the most a step may run, though it kept making progress")
65 }
66 }
67 }
68}