Skip to content
Permalink
Browse files

Fix stack overflow error. Closes #2

- Converting GojiError into ListTicketsError does not resolve in an stack overflow.
- Added command line option to specify path to config file.
  • Loading branch information...
schrieveslaach committed Apr 25, 2019
1 parent be13981 commit 22e4fe491f6ade5f353925b368e935545fab9259
Showing with 17 additions and 14 deletions.
  1. +14 −1 api/src/main.rs
  2. +2 −12 api/src/services/config_service.rs
  3. +1 −1 api/src/tickets.rs
@@ -41,6 +41,7 @@ use crate::models::request_info::RequestInfo;
use crate::services::apps_service::AppsService;
use crate::services::config_service::Config;
use crate::services::docker::DockerInfrastructure;
use clap::{App, Arg};
use rocket::response::NamedFile;
use rocket_cache_response::CacheResponse;
use serde_yaml::{from_reader, to_string, Value};
@@ -90,11 +91,23 @@ fn openapi(request_info: RequestInfo) -> Option<String> {
}

fn main() {
let argument_matches = App::new(crate_name!())
.version(crate_version!())
.arg(
Arg::with_name("config")
.short("c")
.long("config")
.value_name("FILE")
.help("The path to the configuration file")
.takes_value(true),
)
.get_matches();

if cfg!(not(debug_assertions)) {
env_logger::init();
}

let config = match Config::load() {
let config = match Config::load(argument_matches.value_of("config").unwrap_or("config.toml")) {
Ok(config) => config,
Err(e) => {
error!("Cannot load config: {}", e);
@@ -76,18 +76,8 @@ pub struct Config {
}

impl Config {
pub fn load() -> Result<Config, ConfigError> {
let mut f = match File::open("config.toml") {
Err(e) => {
warn!("Cannot find config file ({}) Loading default.", e);
return Ok(Config {
containers: None,
companions: Vec::new(),
jira: None,
});
}
Ok(f) => f,
};
pub fn load(path: &str) -> Result<Config, ConfigError> {
let mut f = File::open(path)?;

let mut contents = String::new();
f.read_to_string(&mut contents)?;
@@ -129,7 +129,7 @@ impl From<ListTicketsError> for HttpApiProblem {
impl From<GojiError> for ListTicketsError {
fn from(err: GojiError) -> Self {
ListTicketsError::UnexpectedError {
internal_message: format!("{}", err),
internal_message: format!("{:?}", err),
}
}
}

0 comments on commit 22e4fe4

Please sign in to comment.
You can’t perform that action at this time.