Skip to content

Commit

Permalink
Merge #601: lianad: print a more helpful error message on startup f…
Browse files Browse the repository at this point in the history
…ailure

d4da2bf daemon bin: try to detect '--help' or '-h' (Antoine Poinsot)
01ce0f1 daemon bin: more helpful error message on config file parsing error (Antoine Poinsot)
222c8bb daemon bin: a more helpful error message on unknown arguments. (Antoine Poinsot)

Pull request description:

  Specifically, link to a sample configuration file. How are users supposed to know how to write the config file otherwise?

  Fixes #559.

ACKs for top commit:
  darosior:
    self-ACK d4da2bf -- trivial.

Tree-SHA512: 7ca05aa0e351c390b67051ad36c2e767b019cf6339d8207e1fdbd1ead47a3d79ab6cd9584c412d98ae876aa7e8ea906885c52261565917a7cd1126798806b5d2
  • Loading branch information
darosior committed Aug 14, 2023
2 parents 6c969ae + d4da2bf commit 0591243
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/bin/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,23 @@ use std::{

use liana::{config::Config, DaemonHandle};

fn print_help_exit() {
eprintln!("A TOML configuration file is required to run lianad. By default lianad looks for a 'config.toml' file in its data directory. A different one may be provided like so: '--conf <config file path>'.");
eprintln!("A documented sample is available at 'contrib/lianad_config_example.toml' in the source tree (https://github.com/wizardsardine/liana/blob/v1.0/contrib/lianad_config_example.toml).");
eprintln!("The default data directory path is a 'liana/' folder in the XDG standard configuration directory for all OSes but Linux ones, where it's '~/.liana/'.");
process::exit(1);
}

fn parse_args(args: Vec<String>) -> Option<PathBuf> {
if args.len() == 1 {
return None;
}

if args.len() != 3 {
eprintln!("Unknown arguments '{:?}'.", args);
eprintln!("Only '--conf <configuration file path>' is supported.");
process::exit(1);
let is_help = args
.iter()
.any(|arg| arg.contains("help") || arg.contains("-h"));
if args.len() != 3 || is_help {
print_help_exit();
}

Some(PathBuf::from(args[2].to_owned()))
Expand Down Expand Up @@ -52,7 +60,8 @@ fn main() {

let config = Config::from_file(conf_file).unwrap_or_else(|e| {
eprintln!("Error parsing config: {}", e);
process::exit(1);
print_help_exit();
unreachable!();
});
setup_logger(config.log_level).unwrap_or_else(|e| {
eprintln!("Error setting up logger: {}", e);
Expand Down

0 comments on commit 0591243

Please sign in to comment.