aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2019-10-20 02:08:37 -0400
committerJesse Luehrs <doy@tozt.net>2019-10-20 02:08:37 -0400
commit1b73a7643ed290a34e03ed85ead5bd5fee92ed7f (patch)
tree5ded4e30f1b4dbdc7a8c3fa77163bd4812d76dbf
parentb1170834339f0f85ae334a889f8a62068d76794a (diff)
downloadteleterm-1b73a7643ed290a34e03ed85ead5bd5fee92ed7f.tar.gz
teleterm-1b73a7643ed290a34e03ed85ead5bd5fee92ed7f.zip
exit with an error if we fail to parse the config file
just using the defaults is confusing for subcommands that don't display errors by default (stream, record, etc)
-rw-r--r--src/cmd.rs6
-rw-r--r--src/cmd/play.rs12
-rw-r--r--src/cmd/record.rs12
-rw-r--r--src/cmd/server.rs12
-rw-r--r--src/cmd/stream.rs12
-rw-r--r--src/cmd/watch.rs12
-rw-r--r--src/error.rs3
7 files changed, 42 insertions, 27 deletions
diff --git a/src/cmd.rs b/src/cmd.rs
index c2d3d8e..b0947d5 100644
--- a/src/cmd.rs
+++ b/src/cmd.rs
@@ -9,7 +9,9 @@ mod watch;
struct Command {
name: &'static str,
cmd: &'static dyn for<'a, 'b> Fn(clap::App<'a, 'b>) -> clap::App<'a, 'b>,
- config: &'static dyn Fn(config::Config) -> Box<dyn crate::config::Config>,
+ config: &'static dyn Fn(
+ config::Config,
+ ) -> Result<Box<dyn crate::config::Config>>,
log_level: &'static str,
}
@@ -76,7 +78,7 @@ pub fn run(matches: &clap::ArgMatches<'_>) -> Result<()> {
.init();
let config = crate::config::config();
- let mut cmd_config = (chosen_cmd.config)(config);
+ let mut cmd_config = (chosen_cmd.config)(config)?;
cmd_config.merge_args(chosen_submatches)?;
log::debug!("{:?}", cmd_config);
cmd_config.run()
diff --git a/src/cmd/play.rs b/src/cmd/play.rs
index 2e41816..7f6657b 100644
--- a/src/cmd/play.rs
+++ b/src/cmd/play.rs
@@ -27,11 +27,13 @@ pub fn cmd<'a, 'b>(app: clap::App<'a, 'b>) -> clap::App<'a, 'b> {
crate::config::Ttyrec::cmd(app.about("Play recorded terminal sessions"))
}
-pub fn config(config: config::Config) -> Box<dyn crate::config::Config> {
- Box::new(config.try_into().unwrap_or_else(|e| {
- log::warn!("failed to parse config data: {}", e);
- Config::default()
- }))
+pub fn config(
+ config: config::Config,
+) -> Result<Box<dyn crate::config::Config>> {
+ let config: Config = config
+ .try_into()
+ .context(crate::error::CouldntParseConfig)?;
+ Ok(Box::new(config))
}
#[allow(clippy::large_enum_variant)]
diff --git a/src/cmd/record.rs b/src/cmd/record.rs
index f36f161..f7fb61d 100644
--- a/src/cmd/record.rs
+++ b/src/cmd/record.rs
@@ -37,11 +37,13 @@ pub fn cmd<'a, 'b>(app: clap::App<'a, 'b>) -> clap::App<'a, 'b> {
))
}
-pub fn config(config: config::Config) -> Box<dyn crate::config::Config> {
- Box::new(config.try_into().unwrap_or_else(|e| {
- log::warn!("failed to parse config data: {}", e);
- Config::default()
- }))
+pub fn config(
+ config: config::Config,
+) -> Result<Box<dyn crate::config::Config>> {
+ let config: Config = config
+ .try_into()
+ .context(crate::error::CouldntParseConfig)?;
+ Ok(Box::new(config))
}
#[allow(clippy::large_enum_variant)]
diff --git a/src/cmd/server.rs b/src/cmd/server.rs
index 6a937c7..a6d620d 100644
--- a/src/cmd/server.rs
+++ b/src/cmd/server.rs
@@ -49,11 +49,13 @@ pub fn cmd<'a, 'b>(app: clap::App<'a, 'b>) -> clap::App<'a, 'b> {
crate::config::Server::cmd(app.about("Run a teleterm server"))
}
-pub fn config(config: config::Config) -> Box<dyn crate::config::Config> {
- Box::new(config.try_into().unwrap_or_else(|e| {
- log::warn!("failed to parse config data: {}", e);
- Config::default()
- }))
+pub fn config(
+ config: config::Config,
+) -> Result<Box<dyn crate::config::Config>> {
+ let config: Config = config
+ .try_into()
+ .context(crate::error::CouldntParseConfig)?;
+ Ok(Box::new(config))
}
fn create_server(
diff --git a/src/cmd/stream.rs b/src/cmd/stream.rs
index e013660..2734484 100644
--- a/src/cmd/stream.rs
+++ b/src/cmd/stream.rs
@@ -91,11 +91,13 @@ pub fn cmd<'a, 'b>(app: clap::App<'a, 'b>) -> clap::App<'a, 'b> {
))
}
-pub fn config(config: config::Config) -> Box<dyn crate::config::Config> {
- Box::new(config.try_into().unwrap_or_else(|e| {
- log::warn!("failed to parse config data: {}", e);
- Config::default()
- }))
+pub fn config(
+ config: config::Config,
+) -> Result<Box<dyn crate::config::Config>> {
+ let config: Config = config
+ .try_into()
+ .context(crate::error::CouldntParseConfig)?;
+ Ok(Box::new(config))
}
struct StreamSession<
diff --git a/src/cmd/watch.rs b/src/cmd/watch.rs
index 4bf9fdd..6ed3ec2 100644
--- a/src/cmd/watch.rs
+++ b/src/cmd/watch.rs
@@ -85,11 +85,13 @@ pub fn cmd<'a, 'b>(app: clap::App<'a, 'b>) -> clap::App<'a, 'b> {
crate::config::Client::cmd(app.about("Watch teleterm streams"))
}
-pub fn config(config: config::Config) -> Box<dyn crate::config::Config> {
- Box::new(config.try_into().unwrap_or_else(|e| {
- log::warn!("failed to parse config data: {}", e);
- Config::default()
- }))
+pub fn config(
+ config: config::Config,
+) -> Result<Box<dyn crate::config::Config>> {
+ let config: Config = config
+ .try_into()
+ .context(crate::error::CouldntParseConfig)?;
+ Ok(Box::new(config))
}
// XXX https://github.com/rust-lang/rust/issues/64362
diff --git a/src/error.rs b/src/error.rs
index eab1c78..c5506c2 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -32,6 +32,9 @@ pub enum Error {
#[snafu(display("couldn't determine the current username"))]
CouldntFindUsername,
+ #[snafu(display("failed to parse configuration: {}", source))]
+ CouldntParseConfig { source: config::ConfigError },
+
#[snafu(display("failed to create tls acceptor: {}", source))]
CreateAcceptor { source: native_tls::Error },