aboutsummaryrefslogtreecommitdiff
path: root/src/error.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/error.rs')
-rw-r--r--src/error.rs29
1 files changed, 21 insertions, 8 deletions
diff --git a/src/error.rs b/src/error.rs
index f303780..7df065d 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -1,15 +1,18 @@
use std::{
env,
fmt::{self, Display},
- io
+ io,
+ string
};
pub enum Error {
+ BadArgs,
BadLengths,
- DuplicateElems(Vec<String>),
+ DupInputElems(Vec<String>),
+ DupOutputElems(Vec<String>),
IOError(io::Error),
- NoArgs,
- NoEditor,
+ Nop,
+ UTF8Error(string::FromUtf8Error),
SpawnFailed(String, io::Error),
}
@@ -17,13 +20,17 @@ impl Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let p = env::args().next().unwrap();
match self {
+ Self::BadArgs => writeln!(f, "Usage: {p} [-0ei] [--] utility [argument ...]"),
Self::BadLengths => writeln!(f, "{p}: Files have been added or removed during editing"),
- Self::DuplicateElems(ds) => ds.iter().try_for_each(
- |d| writeln!(f, "{p}: Multiple files named \"{}\" specified", d)
+ Self::DupInputElems(ds) => ds.iter().try_for_each(
+ |d| writeln!(f, "{p}: Multiple input files named \"{}\" specified", d)
+ ),
+ Self::DupOutputElems(ds) => ds.iter().try_for_each(
+ |d| writeln!(f, "{p}: Multiple output files named \"{}\" specified", d)
),
Self::IOError(e) => writeln!(f, "{p}: {e}"),
- Self::NoArgs => writeln!(f, "Usage: {p} file ..."),
- Self::NoEditor => writeln!(f, "{p}: \"EDITOR\" environment variable is not set"),
+ Self::Nop => Ok(()),
+ Self::UTF8Error(e) => writeln!(f, "{p}: {e}"),
Self::SpawnFailed(ed, e) => writeln!(f, "{p}: Failed to spawn editor \"{ed}\": {e}")
}
}
@@ -34,3 +41,9 @@ impl From<io::Error> for Error {
Self::IOError(e)
}
}
+
+impl From<string::FromUtf8Error> for Error {
+ fn from(e: string::FromUtf8Error) -> Self {
+ Self::UTF8Error(e)
+ }
+}