{"record":{"id":"ad94e7e959683454","repo":"benbjohnson/litestream","slug":"get-initial-size-w","errorCode":null,"errorMessage":"get initial size: %w","messagePattern":"get initial size: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/litestream-test/shrink.go","lineNumber":62,"sourceCode":"\n\tif _, err := os.Stat(c.DB); err != nil {\n\t\treturn fmt.Errorf(\"database does not exist: %w\", err)\n\t}\n\n\tslog.Info(\"Starting database shrink operation\",\n\t\t\"db\", c.DB,\n\t\t\"delete_percentage\", c.DeletePercentage,\n\t\t\"vacuum\", c.Vacuum,\n\t\t\"checkpoint\", c.Checkpoint,\n\t)\n\n\treturn c.shrinkDatabase(ctx)\n}\n\nfunc (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))","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/benbjohnson/litestream/blob/4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3/cmd/litestream-test/shrink.go#L44-L80","documentation":"shrinkDatabase begins by calling getDatabaseSize(c.DB) to record the initial database size; if that fails the error is wrapped as `get initial size: %w`. getDatabaseSize reads the file sizes on disk (main DB plus WAL/SHM sidecars), so this fails on filesystem-level problems, not SQL problems. Note the file existence was already checked in Run, so failures here usually come from a race where the file disappeared, or from sidecar/stat internals.","triggerScenarios":"The database file was removed or renamed between the os.Stat check in Run and the size query; a wrapped stat/os error inside getDatabaseSize (permissions changed, network mount dropped); running against a path on an unmounted volume.","commonSituations":"Concurrent cleanup jobs deleting temp test databases; the DB lives on an ephemeral or network filesystem that went away mid-run; sandboxed CI where /tmp is wiped between steps.","solutions":["Re-run the command; confirm the file still exists right before invocation","Ensure no concurrent job deletes the database while shrink runs","If on a network/ephemeral mount, copy the DB to local disk first","Inspect the wrapped inner error (%w) for the exact syscall failure"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"if _, err := os.Stat(dbPath); err != nil {\n    return fmt.Errorf(\"database disappeared before shrink: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := runShrink(args); err != nil {\n    if strings.Contains(err.Error(), \"get initial size\") {\n        // filesystem race; check file and retry\n        time.Sleep(time.Second)\n        return runShrink(args)\n    }\n    return err\n}","preventionTips":["Do not run cleanup jobs concurrently against the same temp database","Keep the database on stable local storage, not network/ephemeral mounts","Read the wrapped inner error to identify the exact syscall failure"],"tags":["filesystem","sqlite","stat"],"backgroundTag":"file-read-failed","analyzedSha":"4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3","analyzedAt":"2026-09-06T18:29:25.564Z","contentChangedAt":"2026-09-06T18:29:25.564Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}