Skip to content

Commit

Permalink
[cwonder] added error messages for config parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
Max Weidauer committed Apr 15, 2024
1 parent fb66ae0 commit 3413e51
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/cwonder/cwonder_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* http://swonder.sourceforge.net *
* *
* *
* Technische Universität Berlin, Germany *
* Technische Universit�t Berlin, Germany *
* Audio Communication Group *
* www.ak.tu-berlin.de *
* Copyright 2006-2008 *
Expand Down Expand Up @@ -35,6 +35,8 @@
#include <cstring>
#include <fstream>
#include <sstream>
#include <iostream>


#include "wonder_path.h"

Expand Down Expand Up @@ -125,6 +127,7 @@ int CwonderConfig::readConfig() {
std::ifstream fin(cwonderConfigFile.c_str(), std::ios_base::in);

if (!fin.is_open()) {
std::cout << "[Config][ERROR] file " << cwonderConfigFile << " does not exist." << std::endl;
return 1; // file does not exist
}

Expand All @@ -146,6 +149,7 @@ int CwonderConfig::readConfig() {
fin.open(dtdPath.c_str(), std::ios_base::in);

if (!fin.is_open()) {
std::cout << "[Config][ERROR] dtd file does not exist." << std::endl;
return 2; // dtd file does not exist
}

Expand All @@ -154,6 +158,7 @@ int CwonderConfig::readConfig() {
validator.validate(parser.get_document());
}
catch (const xmlpp::validity_error& ex) {
std::cout << "[Config][ERROR] dtd validation error" << std::endl;
return 3; // dtd error
}

Expand All @@ -163,6 +168,7 @@ int CwonderConfig::readConfig() {
}
}
catch (const std::exception& ex) {
std::cout << "[Config][ERROR] XML Error" << std::endl;
return 4; // xml error
}

Expand Down
5 changes: 3 additions & 2 deletions src/cwonder/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ int main(int argc, char* argv[]) {
cwonderConf = new CwonderConfig(argc, argv);

int ret = cwonderConf->readConfig();

if (ret != 0) { std::exit(EXIT_FAILURE); }
if (ret != 0) {
std::cout << "[Config][ERROR]: Could not read config. exiting..." << std::endl;
std::exit(EXIT_FAILURE); }

// make default project path
if (makedirs(cwonderConf->projectPath.c_str(), mode_t(0700)) != 0) {
Expand Down

0 comments on commit 3413e51

Please sign in to comment.