{"record":{"id":"00bd65735f373d35","repo":"sipeed/picoclaw","slug":"get-device-store-w","errorCode":null,"errorMessage":"get device store: %w","messagePattern":"get device store: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"pkg/channels/whatsapp_native/whatsapp_native.go","lineNumber":124,"sourceCode":"\t}\n\tdb.SetMaxOpenConns(1)\n\tdb.SetMaxIdleConns(1)\n\tif _, err = db.ExecContext(ctx, \"PRAGMA foreign_keys = ON\"); err != nil {\n\t\t_ = db.Close()\n\t\treturn fmt.Errorf(\"enable foreign keys: %w\", err)\n\t}\n\n\twaLogger := waLog.Stdout(\"WhatsApp\", \"WARN\", true)\n\tcontainer := sqlstore.NewWithDB(db, sqliteDriver, waLogger)\n\tif err = container.Upgrade(ctx); err != nil {\n\t\t_ = db.Close()\n\t\treturn fmt.Errorf(\"open whatsapp store: %w\", err)\n\t}\n\n\tdeviceStore, err := container.GetFirstDevice(ctx)\n\tif err != nil {\n\t\t_ = container.Close()\n\t\treturn fmt.Errorf(\"get device store: %w\", err)\n\t}\n\n\tclient := whatsmeow.NewClient(deviceStore, waLogger)\n\n\t// Create runCtx/runCancel BEFORE registering event handler and starting\n\t// goroutines so that Stop() can cancel them at any time, including during\n\t// the QR-login flow.\n\tc.runCtx, c.runCancel = context.WithCancel(ctx)\n\n\tclient.AddEventHandler(c.eventHandler)\n\n\tc.mu.Lock()\n\tc.container = container\n\tc.client = client\n\tc.mu.Unlock()\n\n\t// cleanupOnError clears struct references and releases resources when\n\t// Start() fails after fields are already assigned.  This prevents","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/sipeed/picoclaw/blob/49183d7e8daed0dba89ddbb6fcb60089401d9680/pkg/channels/whatsapp_native/whatsapp_native.go#L106-L142","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Stop other processes using the same storePath.","Run sqlite3 integrity_check on store.db; if corrupt, back up and delete the store, then re-pair with a new QR scan.","If ctx was cancelled, fix the caller that aborts Start early and retry.","Check disk health/permissions on the store volume."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := ch.Start(ctx); err != nil {\n    if strings.Contains(err.Error(), \"get device store\") {\n        // last resort: move store aside and restart for a fresh pairing session\n    }\n}","preventionTips":["Keep regular backups of the whatsapp store directory.","Avoid killing the process during pairing writes.","One process per store to prevent lock contention."],"tags":["whatsapp","whatsmeow","device-store","sqlite","corruption"],"backgroundTag":null,"analyzedSha":"49183d7e8daed0dba89ddbb6fcb60089401d9680","analyzedAt":"2026-08-15T21:55:41.315Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}