talmacschen-arch commented on code in PR #97:
URL: https://github.com/apache/cloudberry-backup/pull/97#discussion_r3159533991


##########
gpbackman/gpbckpconfig/utils_db.go:
##########
@@ -21,15 +21,38 @@ package gpbckpconfig
 
 import (
        "database/sql"
+       "errors"
        "fmt"
+       "os"
        "strings"
 
        "github.com/apache/cloudberry-backup/history"
 )
 
-// OpenHistoryDB opens the history backup database.
+// OpenHistoryDB opens an existing gpbackup_history.db SQLite database.
+//
+// The path is opened with the SQLite "rw" URI mode so that a missing file
+// produces a clear error rather than being silently created as an empty
+// database (which would later fail with a confusing "no such table: backups"
+// when callers issue queries). Existence is also pre-checked with os.Stat to
+// surface a friendly error message that points the caller at the relevant
+// flag and environment variables.
 func OpenHistoryDB(historyDBPath string) (*sql.DB, error) {
-       db, err := sql.Open("sqlite3", historyDBPath)
+       if _, err := os.Stat(historyDBPath); err != nil {
+               if errors.Is(err, os.ErrNotExist) {
+                       return nil, fmt.Errorf(
+                               "gpbackup history database file not found: %s. 
"+
+                                       "Specify the path via --history-db, run 
gpbackman from "+
+                                       "the directory that contains 
gpbackup_history.db, or "+
+                                       "pass --auto-load-history-db to resolve 
it from "+
+                                       "$COORDINATOR_DATA_DIRECTORY (or 
$MASTER_DATA_DIRECTORY)",
+                               historyDBPath,
+                       )
+               }
+               return nil, err

Review Comment:
   Good catch, applied in 70097db8 — wrapped with fmt.Errorf("stat history db 
%q: %w", historyDBPath, err) to keep errors.Is/As working while adding 
path/operation     context. Thanks! 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to