{"record":{"id":"635b9b30d8187543","repo":"benbjohnson/litestream","slug":"open-database-w","errorCode":null,"errorMessage":"open database: %w","messagePattern":"open database: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/litestream-test/load.go","lineNumber":80,"sourceCode":"\t}\n\n\tslog.Info(\"Starting load generation\",\n\t\t\"db\", c.DB,\n\t\t\"write_rate\", c.WriteRate,\n\t\t\"duration\", c.Duration,\n\t\t\"pattern\", c.Pattern,\n\t\t\"payload_size\", c.PayloadSize,\n\t\t\"read_ratio\", c.ReadRatio,\n\t\t\"workers\", c.Workers,\n\t)\n\n\treturn c.generateLoad(ctx)\n}\n\nfunc (c *LoadCommand) generateLoad(ctx context.Context) error {\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\tdb.SetMaxOpenConns(c.Workers + 1)\n\tdb.SetMaxIdleConns(c.Workers)\n\n\tif err := c.ensureTestTable(db); err != nil {\n\t\treturn fmt.Errorf(\"ensure test table: %w\", err)\n\t}\n\n\tctx, cancel := context.WithTimeout(ctx, c.Duration)\n\tdefer cancel()\n\n\tsigChan := make(chan os.Signal, 1)\n\tsignal.Notify(sigChan, os.Interrupt, syscall.SIGTERM)\n\tgo func() {\n\t\t<-sigChan\n\t\tslog.Info(\"Received interrupt signal, stopping load generation\")","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/benbjohnson/litestream/blob/4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3/cmd/litestream-test/load.go#L62-L98","documentation":"In generateLoad, `sql.Open(\"sqlite3\", c.DB+\"?_journal_mode=WAL\")` failed and the error is wrapped as \"open database\". Note that database/sql's Open is lazy and mostly validates the DSN/driver; real connection failures usually surface on first use, so this error typically indicates a bad DSN, an unregistered driver (build-tag/CGO issue with the sqlite3 driver), or an immediate driver-level open failure.","triggerScenarios":"Calling `litestream-test load -db <path>` where the resulting DSN `<path>?_journal_mode=WAL` is rejected by the driver, the sqlite3 driver is not imported/available in the binary, or the driver immediately fails to open the file (e.g., unreadable path).","commonSituations":"Special characters in the DB path corrupting the DSN; a build without the sqlite3 driver registered; file permissions blocking the driver's open; very unusual DSN combos when the path itself contains '?' or other DSN-significant characters.","solutions":["Check that the -db path is valid, readable, and contains no characters (like '?') that would break the DSN; rename or quote/escape if needed.","Verify the binary was built with the sqlite3 driver imported (blank import of the driver package); rebuild with CGO or the driver's pure-Go variant as required.","Run `litestream-test load -db <path>` on a known-good database (created by populate) to isolate DSN vs environment issues."],"exampleFix":"// before\ndb, err := sql.Open(\"sqlite3\", c.DB+\"?_journal_mode=WAL\")\nif err != nil {\n    return fmt.Errorf(\"open database: %w\", err)\n}\n// after — surface driver/DSN issues eagerly with a ping\ndb, err := sql.Open(\"sqlite3\", c.DB+\"?_journal_mode=WAL\")\nif err != nil {\n    return fmt.Errorf(\"open database: %w\", err)\n}\nif err := db.Ping(); err != nil {\n    return fmt.Errorf(\"open database: %w\", err)\n}","handlingStrategy":"try-catch","validationCode":"// pre-check the path and DSN before invoking\nif (dbPath.includes(\"?\")) throw new Error(\"DB path must not contain DSN-significant characters: \" + dbPath);","typeGuard":null,"tryCatchPattern":"try {\n  await run(\"litestream-test\", [\"load\", \"-db\", dbPath]);\n} catch (e) {\n  if (String(e).includes(\"open database\")) {\n    console.error(`Failed to open ${dbPath}: check the sqlite3 driver build (CGO/pure-Go) and that the path is DSN-safe`);\n  }\n  throw e;\n}","preventionTips":["Keep DB paths free of '?' and other DSN-significant characters.","Build the harness with the sqlite3 driver properly imported/registered.","Smoke-test with a database created by populate before production runs."],"tags":["sqlite","database","cli"],"backgroundTag":"file-open-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"}