sipeed/picoclaw · critical

get device store: %w

Error message

get device store: %w

What it means

Returned by WhatsAppNativeChannel.Start when sqlstore.Container.GetFirstDevice(ctx) fails to load the (single) device row from the session store. GetFirstDevice is the first schema-aware read after Upgrade; it fails on unreadable/corrupt whatsmeow tables, context cancellation, or a locked database. The container is closed before returning.

Source

Thrown at pkg/channels/whatsapp_native/whatsapp_native.go:124

	}
	db.SetMaxOpenConns(1)
	db.SetMaxIdleConns(1)
	if _, err = db.ExecContext(ctx, "PRAGMA foreign_keys = ON"); err != nil {
		_ = db.Close()
		return fmt.Errorf("enable foreign keys: %w", err)
	}

	waLogger := waLog.Stdout("WhatsApp", "WARN", true)
	container := sqlstore.NewWithDB(db, sqliteDriver, waLogger)
	if err = container.Upgrade(ctx); err != nil {
		_ = db.Close()
		return fmt.Errorf("open whatsapp store: %w", err)
	}

	deviceStore, err := container.GetFirstDevice(ctx)
	if err != nil {
		_ = container.Close()
		return fmt.Errorf("get device store: %w", err)
	}

	client := whatsmeow.NewClient(deviceStore, waLogger)

	// Create runCtx/runCancel BEFORE registering event handler and starting
	// goroutines so that Stop() can cancel them at any time, including during
	// the QR-login flow.
	c.runCtx, c.runCancel = context.WithCancel(ctx)

	client.AddEventHandler(c.eventHandler)

	c.mu.Lock()
	c.container = container
	c.client = client
	c.mu.Unlock()

	// cleanupOnError clears struct references and releases resources when
	// Start() fails after fields are already assigned.  This prevents

View on GitHub (pinned to 49183d7e8d)

Solutions

  1. Stop other processes using the same storePath.
  2. Run sqlite3 integrity_check on store.db; if corrupt, back up and delete the store, then re-pair with a new QR scan.
  3. If ctx was cancelled, fix the caller that aborts Start early and retry.
  4. Check disk health/permissions on the store volume.
Defensive patterns

Strategy: fallback

Try / catch

if err := ch.Start(ctx); err != nil {
    if strings.Contains(err.Error(), "get device store") {
        // last resort: move store aside and restart for a fresh pairing session
    }
}

Prevention

When it happens

Trigger: Start(ctx) right after a successful Upgrade, but the device table read errors: corrupt rows from an aborted write, DB locked by a concurrent reader, or the run context cancelled during Start.

Common situations: Store database corrupted (crash during prior session); another whatsmeow client still holds the file; process/container killed during a previous pairing write. Rare in healthy setups.

Related errors


AI-assisted analysis of sipeed/picoclaw@49183d7e8d (2026-08-15). Data as JSON: /api/errors/00bd65735f373d35. Report an issue: GitHub.