{"record":{"id":"00f7172a930e2f33","repo":"1Panel-dev/1Panel","slug":"init-s-db-file-failed-err-v","errorCode":null,"errorMessage":"init %s db file failed, err: %v","messagePattern":"init (.+?) db file failed, err: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"agent/utils/common/sqlite.go","lineNumber":23,"sourceCode":"\t\"log\"\n\t\"os\"\n\t\"path\"\n\t\"time\"\n\n\t\"github.com/1Panel-dev/1Panel/agent/global\"\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 LoadDBConnByPathWithErr(fullPath, dbName string) (*gorm.DB, error) {\n\tif _, err := createDirWhenNotExist(true, path.Dir(fullPath)); err != nil {\n\t\treturn nil, 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 {","sourceCodeStart":5,"sourceCodeEnd":41,"githubUrl":"https://github.com/1Panel-dev/1Panel/blob/5ac7c808815b0691009cd390414f03471312262f/agent/utils/common/sqlite.go#L5-L41","documentation":"Panic in LoadDBConnByPath when the SQLite db file does not exist (os.Stat error) and os.Create(fullPath) also fails. The dbName is interpolated, so the message names which database (core/agent/etc.) could not be initialized.","triggerScenarios":"First boot or reset: os.Stat reports the file missing, then os.Create fails with e.g. 'permission denied' on the parent dir, 'read-only file system', or 'no such file or directory' because a deeper path component is absent.","commonSituations":"Parent directory removed after a failed cleanup; dir exists but without write permission for the agent user; db path on a read-only or full volume; container started with wrong volume mount.","solutions":["Create and permission the parent directory: mkdir -p <parent> && chown <agent user> <parent>, then restart the agent","Confirm the volume is writable and not full: touch <parent>/.write-test; df -h","As a last resort restore the default layout (reinstall 1Panel / 1pctl restore) so db paths are recreated"],"exampleFix":"# before\ndocker logs 1panel: panic: init core db file failed, err: ... permission denied\n# after (on host)\nmkdir -p /opt/1panel/db && chown -R 1000:1000 /opt/1panel/db && docker restart 1panel","handlingStrategy":"validation","validationCode":"sudo -u <agent-user> sh -c 'mkdir -p $(dirname /opt/1panel/db/core.db) && touch /opt/1panel/db/.wtest && rm /opt/1panel/db/.wtest' && echo ok","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Smoke-test write access to the db directory as the service user before startup","Prefer LoadDBConnByPathWithErr-style error returns in new code paths so callers can report instead of crashing"],"tags":["sqlite","permissions","go","panic","filesystem"],"backgroundTag":null,"analyzedSha":"5ac7c808815b0691009cd390414f03471312262f","analyzedAt":"2026-08-15T14:02:06.953Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}