DiagnoseDBOpenError provides a more helpful error message when SQLite fails to open/create a database file.
(path string, originalErr error)
| 64 | // DiagnoseDBOpenError provides a more helpful error message when SQLite |
| 65 | // fails to open/create a database file. |
| 66 | func DiagnoseDBOpenError(path string, originalErr error) error { |
| 67 | dir := filepath.Dir(path) |
| 68 | |
| 69 | info, err := os.Stat(dir) |
| 70 | if err != nil { |
| 71 | if os.IsNotExist(err) { |
| 72 | return fmt.Errorf("cannot create database at %q: directory %q does not exist", path, dir) |
| 73 | } |
| 74 | return fmt.Errorf("cannot create database at %q: %w", path, err) |
| 75 | } |
| 76 | |
| 77 | if !info.IsDir() { |
| 78 | return fmt.Errorf("cannot create database at %q: %q is not a directory", path, dir) |
| 79 | } |
| 80 | |
| 81 | return fmt.Errorf("cannot create database at %q: permission denied or file cannot be created in %q (original error: %w)", path, dir, originalErr) |
| 82 | } |
| 83 | |
| 84 | // CheckpointAndClose runs a final WAL checkpoint and closes the database. |
| 85 | // The TRUNCATE checkpoint folds the -wal file back into the main database |
no test coverage detected