{"record":{"id":"db67e56e8f4408d0","repo":"benbjohnson/litestream","slug":"get-table-list-w","errorCode":null,"errorMessage":"get table list: %w","messagePattern":"get table list: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/litestream-test/shrink.go","lineNumber":77,"sourceCode":"func (c *ShrinkCommand) shrinkDatabase(ctx context.Context) error {\n\tinitialSize, err := getDatabaseSize(c.DB)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"get initial size: %w\", err)\n\t}\n\n\tslog.Info(\"Initial database size\",\n\t\t\"size_mb\", initialSize/1024/1024,\n\t)\n\n\tdb, err := sql.Open(\"sqlite3\", c.DB+\"?_journal_mode=WAL\")\n\tif err != nil {\n\t\treturn fmt.Errorf(\"open database: %w\", err)\n\t}\n\tdefer db.Close()\n\n\ttables, err := c.getTableList(db)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"get table list: %w\", err)\n\t}\n\n\tslog.Info(\"Found tables\", \"count\", len(tables))\n\n\ttotalDeleted := int64(0)\n\tfor _, table := range tables {\n\t\tdeleted, err := c.deleteFromTable(db, table)\n\t\tif err != nil {\n\t\t\tslog.Error(\"Failed to delete from table\", \"table\", table, \"error\", err)\n\t\t\tcontinue\n\t\t}\n\t\ttotalDeleted += deleted\n\t\tslog.Info(\"Deleted rows from table\",\n\t\t\t\"table\", table,\n\t\t\t\"rows_deleted\", deleted,\n\t\t)\n\t}\n","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/benbjohnson/litestream/blob/4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3/cmd/litestream-test/shrink.go#L59-L95","documentation":"After opening the database, shrinkDatabase calls c.getTableList(db), which queries sqlite_master for user tables (excluding sqlite_% and load_test). Any error from that query or from scanning rows is wrapped as `get table list: %w`. This indicates the schema read failed — usually a database-level problem such as corruption or a locked/busy database.","triggerScenarios":"The opened file is not a valid SQLite database (sql.Open succeeded lazily; the first real query fails with 'file is not a database'); the database is locked by another writer with no busy timeout; disk I/O error while reading sqlite_master.","commonSituations":"Pointing the tool at a non-SQLite file (e.g. an LTX file, WAL fragment, or text file renamed to .db); another process holds an exclusive lock during heavy load testing; reading a database written by a newer SQLite with an unsupported file format.","solutions":["Verify the file is a real SQLite database: `file <path>` or `sqlite3 <path> '.tables'`","Close or wait for other processes holding locks on the database, then retry","Add a busy timeout to the DSN (e.g. &_busy_timeout=5000) if concurrent access is expected","Check the wrapped inner error for 'not a database' vs 'database is locked' and act accordingly"],"exampleFix":"// before\ndb, err := sql.Open(\"sqlite3\", c.DB+\"?_journal_mode=WAL\")\n// after\ndb, err := sql.Open(\"sqlite3\", c.DB+\"?_journal_mode=WAL&_busy_timeout=5000\")","handlingStrategy":"retry","validationCode":"// confirm the file is a valid SQLite database before invoking\nif header, err := os.ReadFile(dbPath); err == nil && len(header) >= 16 {\n    if string(header[:16]) != \"SQLite format 3\\x00\" {\n        return fmt.Errorf(\"%s is not a SQLite database\", dbPath)\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := runShrink(args); err != nil {\n    if strings.Contains(err.Error(), \"get table list\") {\n        if strings.Contains(err.Error(), \"locked\") {\n            time.Sleep(2 * time.Second)\n            return runShrink(args)\n        }\n    }\n    return err\n}","preventionTips":["Never point the tool at LTX files, WAL fragments, or renamed non-SQLite files","Stop concurrent writers or add a busy timeout to the DSN before heavy test runs","Check the wrapped inner error: 'not a database' vs 'database is locked' need different fixes"],"tags":["sqlite","query","schema","locked"],"backgroundTag":"database-query-failed","analyzedSha":"4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3","analyzedAt":"2026-09-06T18:29:25.564Z","contentChangedAt":"2026-09-06T18:29:25.564Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}