Skip to content

Commit 3e67e10

Browse files
committed
refactor: Move config test mode check before directory verification
Relocate the config test mode validation to execute immediately after configuration parsing succeeds, before any filesystem operations. This provides faster feedback when using --config-test flag and follows the fail-fast principle.
1 parent d15634a commit 3e67e10

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

src/main.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,22 @@ int main(int argc, char* argv[]) {
189189
return 1;
190190
}
191191

192+
// Config test mode: validate and exit
193+
if (config_test_mode) {
194+
std::cout << "Configuration file syntax is OK\n";
195+
std::cout << "Configuration details:\n";
196+
std::cout << " MySQL: " << config.mysql.user << "@" << config.mysql.host << ":" << config.mysql.port << "\n";
197+
std::cout << " Tables: " << config.tables.size() << "\n";
198+
for (const auto& table : config.tables) {
199+
std::cout << " - " << table.name << " (primary_key: " << table.primary_key
200+
<< ", ngram_size: " << table.ngram_size << ")\n";
201+
}
202+
std::cout << " API TCP: " << config.api.tcp.bind << ":" << config.api.tcp.port << "\n";
203+
std::cout << " Replication: " << (config.replication.enable ? "enabled" : "disabled") << "\n";
204+
std::cout << " Logging level: " << config.logging.level << "\n";
205+
return 0;
206+
}
207+
192208
// Verify dump directory permissions
193209
try {
194210
std::filesystem::path dump_dir(config.dump.dir);
@@ -216,22 +232,6 @@ int main(int argc, char* argv[]) {
216232
return 1;
217233
}
218234

219-
// Config test mode: validate and exit
220-
if (config_test_mode) {
221-
std::cout << "Configuration file syntax is OK\n";
222-
std::cout << "Configuration details:\n";
223-
std::cout << " MySQL: " << config.mysql.user << "@" << config.mysql.host << ":" << config.mysql.port << "\n";
224-
std::cout << " Tables: " << config.tables.size() << "\n";
225-
for (const auto& table : config.tables) {
226-
std::cout << " - " << table.name << " (primary_key: " << table.primary_key
227-
<< ", ngram_size: " << table.ngram_size << ")\n";
228-
}
229-
std::cout << " API TCP: " << config.api.tcp.bind << ":" << config.api.tcp.port << "\n";
230-
std::cout << " Replication: " << (config.replication.enable ? "enabled" : "disabled") << "\n";
231-
std::cout << " Logging level: " << config.logging.level << "\n";
232-
return 0;
233-
}
234-
235235
// Initialize table contexts for all configured tables
236236
spdlog::info("Initializing {} table(s)...", config.tables.size());
237237
std::unordered_map<std::string, std::unique_ptr<TableContext>> table_contexts;

0 commit comments

Comments
 (0)