{"record":{"id":"56c6e08547ba4958","repo":"1Panel-dev/1Panel","slug":"init-s-db-file-failed-err-v-56c6e0","errorCode":null,"errorMessage":"init %s db file failed, err: %v","messagePattern":"init (.+?) db file failed, err: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/utils/common/sqlite.go","lineNumber":22,"sourceCode":"\t\"fmt\"\n\t\"log\"\n\t\"os\"\n\t\"path\"\n\t\"time\"\n\n\t\"github.com/glebarez/sqlite\"\n\t\"gorm.io/gorm\"\n\t\"gorm.io/gorm/logger\"\n)\n\nfunc LoadDBConnByPath(fullPath, dbName string) *gorm.DB {\n\tif _, err := CreateDirWhenNotExist(true, path.Dir(fullPath)); err != nil {\n\t\tpanic(fmt.Errorf(\"init db dir failed, err: %v\", err))\n\t}\n\tif _, err := os.Stat(fullPath); err != nil {\n\t\tf, err := os.Create(fullPath)\n\t\tif err != nil {\n\t\t\tpanic(fmt.Errorf(\"init %s db file failed, err: %v\", dbName, err))\n\t\t}\n\t\t_ = f.Close()\n\t}\n\n\tdb, err := GetDBWithPath(fullPath)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\treturn db\n}\n\nfunc CloseDB(db *gorm.DB) {\n\tsqlDB, err := db.DB()\n\tif err != nil {\n\t\treturn\n\t}\n\t_ = sqlDB.Close()\n}","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/1Panel-dev/1Panel/blob/5ac7c808815b0691009cd390414f03471312262f/core/utils/common/sqlite.go#L4-L40","documentation":"Error \"init %s db file failed, err: %v\" thrown in 1Panel-dev/1Panel.","triggerScenarios":"Thrown at core/utils/common/sqlite.go:22 when the library encounters an invalid state.","commonSituations":"Occurs when the sqlite database file does not exist and os.Create fails to create it (permission denied, read-only filesystem, or full disk). The process panics. Defense: pre-create the database directory and file with correct ownership, verify write permissions and available disk space, and treat this panic as a fatal environment misconfiguration rather than a transient error.","solutions":["Check that the database directory exists and is writable by the 1Panel core process before the db file is created.","Verify the disk is not full (`df -h`) and the filesystem is not read-only.","Check file permissions and ownership on the target db file path; remove or fix a broken file with the same name.","If the path contains a stale directory entry or symlink, remove it and restart the service so the file can be created cleanly."],"exampleFix":"ls -l /opt/1panel/db/  # inspect the path, fix ownership: chown root:root /opt/1panel/db && systemctl restart 1panel","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"5ac7c808815b0691009cd390414f03471312262f","analyzedAt":"2026-08-15T14:02:06.953Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}