{"record":{"id":"d2d98050a97f6c95","repo":"MHSanaei/3x-ui","slug":"source-sqlite-not-found-at-s-w","errorCode":null,"errorMessage":"source sqlite not found at %s: %w","messagePattern":"source sqlite not found at (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/database/dump_sqlite.go","lineNumber":34,"sourceCode":"\n// DumpSQLite writes a portable SQL text dump of the SQLite database at srcPath\n// to outPath. The output mirrors the `sqlite3 .dump` format (schema + data +\n// indexes wrapped in a transaction), so it can be rebuilt with RestoreSQLite or\n// loaded by the sqlite3 CLI. The source database is opened read-only in effect\n// and left untouched.\nfunc DumpSQLite(srcPath, outPath string) error {\n\tdata, err := DumpSQLiteToBytes(srcPath)\n\tif err != nil {\n\t\treturn err\n\t}\n\treturn os.WriteFile(outPath, data, 0o644)\n}\n\n// DumpSQLiteToBytes builds the same `sqlite3 .dump`-style SQL text as DumpSQLite\n// but returns it in memory, which the panel uses to stream a migration download.\nfunc DumpSQLiteToBytes(srcPath string) ([]byte, error) {\n\tif _, err := os.Stat(srcPath); err != nil {\n\t\treturn nil, fmt.Errorf(\"source sqlite not found at %s: %w\", srcPath, err)\n\t}\n\n\tgdb, err := gorm.Open(sqlite.Open(srcPath), &gorm.Config{Logger: logger.Discard})\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tsqlDB, err := gdb.DB()\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tdefer sqlDB.Close()\n\n\tvar b strings.Builder\n\tb.WriteString(\"PRAGMA foreign_keys=OFF;\\n\")\n\tb.WriteString(\"BEGIN TRANSACTION;\\n\")\n\n\t// Tables in creation order, each followed by its data.\n\ttype object struct{ name, ddl string }","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/MHSanaei/3x-ui/blob/ad32144c42455696ea9f14e12168beac3e25f5d2/internal/database/dump_sqlite.go#L16-L52","documentation":"DumpSQLiteToBytes stats srcPath first and wraps the failure — the SQLite file to dump does not exist (or is unreadable at the OS level). Everything downstream (gorm open, .dump-style SQL generation) is skipped. Usually a wrong path or a database that was never initialized on this host.","triggerScenarios":"Calling DumpSQLite with a path other than the real DB location (e.g. /etc/x-ui/x-ui.db when the panel runs from a different dir or Windows layout); running the dump before first panel start created the DB; a typo'd path argument.","commonSituations":"Manual migration prep where the operator guesses the DB path; Docker setups where the volume is mounted elsewhere; fresh installs invoking dump tooling immediately.","solutions":["Confirm the actual DB path (default /etc/x-ui/x-ui.db on Linux; executable dir on Windows) — check the running panel's config/logs.","If the DB was never created, start the panel once so InitDB creates it, then dump.","Check for mount/permission issues making an existing file invisible to the process (os.Stat error text will say which)."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if _, err := os.Stat(srcPath); err != nil {\n    return fmt.Errorf(\"sqlite source missing: %w\", err)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Derive srcPath from the panel's actual DB location instead of assuming /etc/x-ui/x-ui.db (Windows differs).","Start the panel once before dumping so the DB file exists."],"tags":["database","sqlite","dump","filesystem"],"backgroundTag":null,"analyzedSha":"ad32144c42455696ea9f14e12168beac3e25f5d2","analyzedAt":"2026-08-15T11:13:23.905Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}