MCPcopy Index your code
hub / github.com/docker/docker-agent / DiagnoseDBOpenError

Function DiagnoseDBOpenError

pkg/sqliteutil/sqlite.go:66–82  ·  view source on GitHub ↗

DiagnoseDBOpenError provides a more helpful error message when SQLite fails to open/create a database file.

(path string, originalErr error)

Source from the content-addressed store, hash-verified

64// DiagnoseDBOpenError provides a more helpful error message when SQLite
65// fails to open/create a database file.
66func 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

Callers 2

OpenDBFunction · 0.85

Calls 1

DirMethod · 0.80

Tested by

no test coverage detected