Skip to content

Commit 4cb62d3

Browse files
committed
Input YAML parsing throw useful error messages
1 parent 32a9b10 commit 4cb62d3

1 file changed

Lines changed: 17 additions & 29 deletions

File tree

Code.v05-00/src/YamlInputReader/YamlInputReader.cpp

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ namespace YamlInputReader{
5757
auto userKeys = getYamlKeys(userNode);
5858

5959
for (const auto& key : userKeys) {
60-
if (defaultKeys.find(key) == defaultKeys.end()) {
60+
if (!defaultKeys.contains(key)) {
6161
// The key from the user's YAML does not exist in the default YAML.
6262
std::string errorPath = currentPath.empty() ? key : currentPath + " -> " + key;
6363
throw std::runtime_error("Unknown key found: '" + errorPath + "'");
@@ -94,69 +94,57 @@ namespace YamlInputReader{
9494
try {
9595
readSimMenu(input, mergedData["SIMULATION MENU"]);
9696
}
97-
catch (...) {
98-
std::cout << "Something went wrong in reading the SIMULATION MENU! Please double-check your input file with the reference in SampleRunDir!";
99-
exit(1);
97+
catch (const std::exception& e) {
98+
throw std::runtime_error("Something went wrong in reading the SIMULATION MENU! Please double-check your input file with the reference in Code.v05-00/defaults/input.yaml\n Exception: " + std::string(e.what()));
10099
}
101100

102101
try {
103102
readParamMenu(input, mergedData["PARAMETER MENU"]);
104103
}
105-
catch (...) {
106-
std::cout << "Something went wrong in reading the PARAMETER MENU! Please double-check your input file with the reference in SampleRunDir!";
107-
exit(1);
104+
catch (const std::exception& e) {
105+
throw std::runtime_error("Something went wrong in reading the PARAMETER MENU! Please double-check your input file with the reference in Code.v05-00/defaults/input.yaml\n Exception: " + std::string(e.what()));
108106
}
109107

110108
try {
111109
readTransportMenu(input, mergedData["TRANSPORT MENU"]);
112110
}
113-
catch (...) {
114-
std::cout << "Something went wrong in reading the TRANSPORT MENU! Please double-check your input file with the reference in SampleRunDir!";
115-
exit(1);
111+
catch (const std::exception& e) {
112+
throw std::runtime_error("Something went wrong in reading the TRANSPORT MENU! Please double-check your input file with the reference in Code.v05-00/defaults/input.yaml\n Exception: " + std::string(e.what()));
116113
}
117114

118115
try {
119116
readChemMenu(input, mergedData["CHEMISTRY MENU"]);
120117
}
121-
catch (...) {
122-
std::cout << "Something went wrong in reading the CHEMISTRY MENU! Please double-check your input file with the reference in SampleRunDir!";
123-
exit(1);
118+
catch (const std::exception& e) {
119+
throw std::runtime_error("Something went wrong in reading the CHEMISTRY MENU! Please double-check your input file with the reference in Code.v05-00/defaults/input.yaml\n Exception: " + std::string(e.what()));
124120
}
125121

126122
try {
127123
readAeroMenu(input, mergedData["AEROSOL MENU"]);
128124
}
129-
catch (...) {
130-
std::cout << "Something went wrong in reading the AEROSOL MENU! Please double-check your input file with the reference in SampleRunDir!";
131-
exit(1);
125+
catch (const std::exception& e) {
126+
throw std::runtime_error("Something went wrong in reading the AEROSOL MENU! Please double-check your input file with the reference in Code.v05-00/defaults/input.yaml\n Exception: " + std::string(e.what()));
132127
}
133128

134129
try {
135130
readMetMenu(input, mergedData["METEOROLOGY MENU"]);
136131
}
137-
catch (const std::invalid_argument& e) {
138-
std::cerr << "ERROR: " << e.what() << std::endl;
139-
exit(1);
140-
}
141-
catch (...) {
142-
std::cout << "Something went wrong in reading the METEOROLOGY MENU! Please double-check your input file with the reference in SampleRunDir!";
143-
exit(1);
132+
catch (const std::exception& e) {
133+
throw std::runtime_error("Something went wrong in reading the METEOROLOGY MENU! Please double-check your input file with the reference in Code.v05-00/defaults/input.yaml\n Exception: " + std::string(e.what()));
144134
}
145135

146136
try {
147137
readDiagMenu(input, mergedData["DIAGNOSTIC MENU"]);
148138
}
149-
catch (...) {
150-
std::cout << "Something went wrong in reading the DIAGNOSTIC MENU! Please double-check your input file with the reference in SampleRunDir!";
151-
exit(1);
139+
catch (const std::exception& e) {
140+
throw std::runtime_error("Something went wrong in reading the DIAGNOSTIC MENU! Please double-check your input file with the reference in Code.v05-00/defaults/input.yaml\n Exception: " + std::string(e.what()));
152141
}
153142

154143
try {
155144
readAdvancedMenu(input, mergedData["ADVANCED OPTIONS MENU"]);
156145
}
157-
catch (...) {
158-
std::cout << "Something went wrong in reading the ADVANCED OPTIONS MENU! Please double-check your input file with the reference in SampleRunDir!";
159-
exit(1);
146+
catch (const std::exception& e) {
147+
throw std::runtime_error("Something went wrong in reading the ADVANCED OPTIONS MENU! Please double-check your input file with the reference in Code.v05-00/defaults/input.yaml\n Exception: " + std::string(e.what()));
160148
}
161149
}
162150
void readSimMenu(OptInput& input, const YAML::Node& simNode){

0 commit comments

Comments
 (0)