gastownhall/beads · error

measure active database directory %q: %w

Error message

measure active database directory %q: %w

What it means

ActiveDatabaseSize measures the on-disk size of the active Dolt database directory via storage.MeasureDirectorySize; this error wraps that failure and includes the directory path. It reflects filesystem-level problems (missing dir, permission, stat errors), not the SQL server.

Source

Thrown at internal/storage/dolt/store.go:2867

	if s.dbPath == "" {
		return ""
	}
	return filepath.Join(s.dbPath, s.database)
}

// ActiveDatabaseSize returns the approximate size of the active database.
// External server instances have no authoritative local path and report the
// capability as unsupported even if a stale client-local directory exists.
func (s *DoltStore) ActiveDatabaseSize(ctx context.Context) (int64, error) {
	if s.localActiveDatabaseDir == "" {
		return 0, &storage.ErrUnsupported{
			Op:      "ActiveDatabaseSize",
			Backend: "dolt-server",
		}
	}
	size, err := storage.MeasureDirectorySize(ctx, s.localActiveDatabaseDir)
	if err != nil {
		return 0, fmt.Errorf("measure active database directory %q: %w", s.localActiveDatabaseDir, err)
	}
	return size, nil
}

// DoltGC runs Dolt garbage collection to reclaim disk space.
// Pins a single connection to avoid session state loss on pooled *sql.DB.
func (s *DoltStore) DoltGC(ctx context.Context) error {
	conn, err := s.db.Conn(ctx)
	if err != nil {
		return fmt.Errorf("acquire connection for gc: %w", err)
	}
	defer conn.Close()
	return versioncontrolops.DoltGC(ctx, conn)
}

// ListRemoteRefs returns the names of all cached remote-tracking refs.
func (s *DoltStore) ListRemoteRefs(ctx context.Context) ([]string, error) {
	return versioncontrolops.ListRemoteRefs(ctx, s.db)

View on GitHub (pinned to 71377f2769)

Solutions

  1. Verify the directory exists and is readable: ls -la on s.localActiveDatabaseDir and fix permissions (chmod/chown)
  2. If in server mode (no local dir), don't call ActiveDatabaseSize — the Op/Backend metadata in the surrounding code already guards this; ensure store mode is embedded
  3. Recreate/re-initialize the database directory if it was deleted, then retry

Example fix

// before
size, err := store.ActiveDatabaseSize(ctx)
// after
if _, err := os.Stat(dbDir); err != nil {
    // directory missing: initialize store first
}
size, err := store.ActiveDatabaseSize(ctx)
Defensive patterns

Strategy: validation

Validate before calling

// verify the database directory exists and is readable first
info, err := os.Stat(s.localActiveDatabaseDir)
if err != nil {
    // directory missing: initialize the embedded store before sizing
}
if info != nil && !info.IsDir() {
    return errors.New("active database path is not a directory")
}
if f, err := os.Open(s.localActiveDatabaseDir); err != nil {
    return fmt.Errorf("no read permission on %s", s.localActiveDatabaseDir)
} else {
    f.Close()
}

Prevention

When it happens

Trigger: Calling ActiveDatabaseSize when s.localActiveDatabaseDir does not exist (embedded Dolt not yet initialized), the process lacks read permission on the directory, an I/O error occurs walking the directory, or ctx is canceled mid-measurement.

Common situations: Server-mode store (no local dir) incorrectly reporting size; deleted or moved .dolt data directory; running under a different user (container permission mismatch); disk I/O errors.

Related errors


AI-assisted analysis of gastownhall/beads@71377f2769 (2026-08-30). Data as JSON: /api/errors/3eba585e05fb97fc. Report an issue: GitHub.