use crate::diag::{Diagnostic, SgCode};
pub fn supervisor_not_started() -> Diagnostic {
Diagnostic::error(
SgCode::SupervisorOffline,
"no supervisor is running, and no manifest was given to read state from",
)
.note(
"`status` falls back to persisted state when the supervisor is down, \
but that needs a project to read: none was named and none is loaded",
)
.help_cmd("start a supervisor", "sysg start --daemonize")
.help_cmd("read a project off disk", "sysg status -c <config>.yaml")
.help_docs()
}
pub fn supervisor_offline() -> Diagnostic {
Diagnostic::warn(
SgCode::SupervisorOffline,
"no supervisor is running; the state below was read from disk and is unsupervised",
)
.note("processes shown as running survived the supervisor and are now orphaned")
.help_cmd("resume supervision", "sysg start --daemonize")
.help_docs()
}
pub fn supervisor_not_responding() -> Diagnostic {
Diagnostic::warn(
SgCode::SupervisorNotResponding,
"the supervisor is running but did not answer its control socket in time",
)
.note("it may be shutting down or wedged; the reading below may be stale")
.help_cmd("force it down", "sysg stop --supervisor")
.help_docs()
}
pub fn state_inconsistent(detail: impl Into<String>) -> Diagnostic {
Diagnostic::warn(
SgCode::StatusStateInconsistent,
"recorded state disagrees with the live process table",
)
.note(detail)
.help_cmd("see what's running", "sysg status --live")
.help_docs()
}
pub fn snapshot_unavailable(detail: impl Into<String>) -> Diagnostic {
Diagnostic::warn(
SgCode::StatusStateInconsistent,
"the boot completed but its status snapshot could not be published",
)
.note(detail)
.note(
"service startup ran; until the next refresh `sysg status` may still \
report those units as not yet running",
)
.help_cmd("read live state instead", "sysg status --live")
.help_docs()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn snapshot_unavailable_is_sg0009_and_does_not_claim_units_came_up() {
let diag = snapshot_unavailable("lock poisoned");
assert_eq!(diag.code, SgCode::StatusStateInconsistent);
let rendered = diag.render(false);
assert!(rendered.contains("service startup ran"));
assert!(rendered.contains("lock poisoned"));
}
#[test]
fn offline_is_sg0206_and_names_orphans() {
let diag = supervisor_offline();
assert_eq!(diag.code, SgCode::SupervisorOffline);
assert!(diag.render(false).contains("orphaned"));
}
#[test]
fn not_started_is_sg0206_and_says_how_to_start_one() {
let diag = supervisor_not_started();
assert_eq!(diag.code, SgCode::SupervisorOffline);
let rendered = diag.render(false);
assert!(rendered.contains("no supervisor is running"));
assert!(rendered.contains("sysg start --daemonize"));
assert!(!rendered.contains("orphaned"));
}
#[test]
fn not_responding_is_sg0205() {
assert_eq!(
supervisor_not_responding().code,
SgCode::SupervisorNotResponding
);
}
#[test]
fn inconsistent_is_sg0009_and_carries_detail() {
let diag = state_inconsistent("web recorded running but pid 12 is gone");
assert_eq!(diag.code, SgCode::StatusStateInconsistent);
assert!(diag.render(false).contains("pid 12 is gone"));
}
}