about summary refs log tree commit diff
path: root/src/bin
diff options
context:
space:
mode:
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/gn-indexer.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/bin/gn-indexer.rs b/src/bin/gn-indexer.rs
index 3b70945..d437699 100644
--- a/src/bin/gn-indexer.rs
+++ b/src/bin/gn-indexer.rs
@@ -67,6 +67,20 @@ fn main() -> ExitCode {
         publish_filter,
     };
 
+    // Fail loudly BEFORE touching the index when the database is
+    // unreachable: the crawl needs it, and a run must never build an
+    // empty index. The message names SQL_URI/GN4_DB_MODE so the cause is
+    // unambiguous. (The crawl itself also fails, but this makes the
+    // reason explicit and keeps the index untouched by construction.)
+    if let Err(error) = genenetwork4::db::probe() {
+        eprintln!(
+            "gn-indexer: database unreachable (SQL_URI; GN4_DB_MODE={:?}); refusing to build an \
+             index: {error}",
+            config.db_mode
+        );
+        return ExitCode::from(1);
+    }
+
     let result = match mode.as_str() {
         "full" => run_full(&run_config),
         "incremental" => run_incremental(&run_config),