error functions now return a never type

This commit is contained in:
Valerie Wolfe 2024-07-24 20:59:33 -04:00
parent ff30bc1052
commit 8449ae00d6
3 changed files with 13 additions and 16 deletions

View file

@ -36,7 +36,7 @@ pub fn switch(state: &mut State) {
let target: String = match if let Some(inner) = args.get(0) { inner.to_str() } else { None } { let target: String = match if let Some(inner) = args.get(0) { inner.to_str() } else { None } {
None | None |
Some("-") => if let Some(prev) = message(MSG_PREVIOUS) { prev } Some("-") => if let Some(prev) = message(MSG_PREVIOUS) { prev }
else { error::missing_target(); panic!() }, else { error::missing_target() },
Some(inner) => inner.to_owned() Some(inner) => inner.to_owned()
}; };

View file

@ -1,14 +1,14 @@
use std::process::exit; use std::process::exit;
/// no subcommand that matches user input; code 1 /// no subcommand that matches user input; code 1
pub fn no_subcommand(subcommand: String) { pub fn no_subcommand(subcommand: String) -> ! {
eprintln!("remux: no command match for \"{subcommand}\""); eprintln!("remux: no command match for \"{subcommand}\"");
exit(1); exit(1);
} }
/// target session not found; code 2 /// target session not found; code 2
pub fn no_target<S: Into<String>>(target: S) { pub fn no_target<S: Into<String>>(target: S) -> ! {
let target = target.into(); let target = target.into();
eprintln!("remux: no session \"{target}\" exists"); eprintln!("remux: no session \"{target}\" exists");
exit(2); exit(2);
@ -16,26 +16,26 @@ pub fn no_target<S: Into<String>>(target: S) {
/// help topic doesn't exist; code 3 /// help topic doesn't exist; code 3
pub fn no_help(topic: String) { pub fn no_help(topic: String) -> ! {
eprintln!("remux: no help for \"{topic}\""); eprintln!("remux: no help for \"{topic}\"");
exit(3); exit(3);
} }
/// user provided no target; code 4 /// user provided no target; code 4
pub fn missing_target() { pub fn missing_target() -> ! {
eprintln!("remux: no target provided"); eprintln!("remux: no target provided");
exit(4); exit(4);
} }
/// refuse to attach to current session; code 4 /// refuse to attach to current session; code 4
pub fn same_session() { pub fn same_session() -> ! {
eprintln!("remux: cannot attach to same session"); eprintln!("remux: cannot attach to same session");
exit(4); exit(4);
} }
/// a session with the target name already exists; code 4 /// a session with the target name already exists; code 4
pub fn target_exists<S: Into<String>>(target: S) { pub fn target_exists<S: Into<String>>(target: S) -> ! {
let target = target.into(); let target = target.into();
eprintln!("remux: session \"{target}\" already exists"); eprintln!("remux: session \"{target}\" already exists");
exit(4); exit(4);
@ -43,26 +43,26 @@ pub fn target_exists<S: Into<String>>(target: S) {
/// non-terminal environment prevention; code 5 /// non-terminal environment prevention; code 5
pub fn not_terminal() { pub fn not_terminal() -> ! {
eprintln!("remux: not running from a terminal"); eprintln!("remux: not running from a terminal");
exit(5); exit(5);
} }
/// tried to nest while not in a session; code 6 /// tried to nest while not in a session; code 6
pub fn not_nesting() { pub fn not_nesting() -> ! {
eprintln!("remux: inappropriate nesting flag (-n); not in a session"); eprintln!("remux: inappropriate nesting flag (-n); not in a session");
exit(6); exit(6);
} }
/// operation requires nesting flag; code 6 /// operation requires nesting flag; code 6
pub fn prevent_nest() { pub fn prevent_nest() -> ! {
eprintln!("remux: the nesting flag (-n) is required for nesting operation"); eprintln!("remux: the nesting flag (-n) is required for nesting operation");
exit(6); exit(6);
} }
/// operation conflicts with nesting flag; code 6 /// operation conflicts with nesting flag; code 6
pub fn conflict_nest(reason: Option<&'static str>) { pub fn conflict_nest(reason: Option<&'static str>) -> ! {
if let Some(reason) = reason { eprintln!("remux: inappropriate nesting flag (-n): {reason}"); } if let Some(reason) = reason { eprintln!("remux: inappropriate nesting flag (-n): {reason}"); }
else { eprintln!("remux: nesting flag (-n) is inappropriate for this operation."); } else { eprintln!("remux: nesting flag (-n) is inappropriate for this operation."); }
exit(6); exit(6);
@ -70,7 +70,7 @@ pub fn conflict_nest(reason: Option<&'static str>) {
/// tried to run a session command outside a session; code 7 /// tried to run a session command outside a session; code 7
pub fn not_in_session(cmd: &'static str) { pub fn not_in_session(cmd: &'static str) -> ! {
eprintln!("remux: '{cmd}' must be run from within a session"); eprintln!("remux: '{cmd}' must be run from within a session");
exit(7); exit(7);
} }

View file

@ -67,10 +67,7 @@ impl State<'_> {
let from_args = self.target(); let from_args = self.target();
if from_args.is_some() { return from_args; } if from_args.is_some() { return from_args; }
else if let Some(repository) = &self.repository { Some(repository.name.clone()) } else if let Some(repository) = &self.repository { Some(repository.name.clone()) }
else { else { error::missing_target() }
error::missing_target();
None
}
} }
} }