From d49376f71dd8defebf80f901ecb60ab99f0f4906 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Tue, 14 Apr 2026 10:40:44 +0300 Subject: n3: validate SQLite with PingContext after Open Call db.PingContext in storage.Open and authkeys.OpenStore; close DB and return wrapped errors on failure. Add tests for canceled context and invalid directory path. Made-with: Cursor --- internal/storage/db.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'internal/storage/db.go') diff --git a/internal/storage/db.go b/internal/storage/db.go index 14d7050..7b577e7 100644 --- a/internal/storage/db.go +++ b/internal/storage/db.go @@ -40,11 +40,15 @@ type Record struct { func Open(ctx context.Context, path string) (*sql.DB, error) { db, err := sql.Open("sqlite", path) if err != nil { - return nil, err + return nil, fmt.Errorf("open sqlite: %w", err) + } + if err := db.PingContext(ctx); err != nil { + db.Close() + return nil, fmt.Errorf("ping sqlite: %w", err) } if _, err := db.ExecContext(ctx, "PRAGMA foreign_keys = OFF"); err != nil { db.Close() - return nil, err + return nil, fmt.Errorf("pragma foreign_keys: %w", err) } return db, nil } -- cgit v1.2.3