{"record":{"id":"6cee872a00898f6b","repo":"siyuan-note/siyuan","slug":"w-cleanup-failed-v","errorCode":null,"errorMessage":"%w; cleanup failed: %v","messagePattern":"%w; cleanup failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/attribute_view_create.go","lineNumber":245,"sourceCode":"}\n\nfunc cleanupCreatedAttributeView(blockID, avID string) (err error) {\n\tif \"\" != blockID {\n\t\terr = PerformTxSync(&Transaction{DoOperations: []*Operation{{Action: \"delete\", ID: blockID}}})\n\t}\n\tavJSONPath, boxID := av.FindAttributeViewPath(avID)\n\tif \"\" != avJSONPath && filelock.IsExist(avJSONPath) {\n\t\terr = errors.Join(err, filelock.RemoveWithoutFatal(avJSONPath))\n\t}\n\tcache.RemoveAVDataInBox(avID, boxID)\n\treturn\n}\n\nfunc databaseCreationError(createErr, cleanupErr error) error {\n\tif nil == cleanupErr {\n\t\treturn createErr\n\t}\n\treturn fmt.Errorf(\"%w; cleanup failed: %v\", createErr, cleanupErr)\n}\n","sourceCodeStart":227,"sourceCodeEnd":247,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/attribute_view_create.go#L227-L247","documentation":"When database creation fails, CreateAttributeViewDatabase attempts to clean up partially created artifacts (block, attribute view, tree). If the original create error occurred AND the cleanup also failed, databaseCreationError combines them: the original error is wrapped (%w) and the cleanup failure is appended, so both root cause and cleanup failure are visible. The caller sees a single compound error indicating a partially created database may remain on disk.","triggerScenarios":"Any failure inside CreateAttributeViewDatabase (invalid parent, wrong layout, tree write error) followed by a failing cleanup step, e.g. removeAttributeViewBlock or the tree removal returning an error (file locks, disk full, corrupted .sy).","commonSituations":"Disk-full or permission problems where both creation and rollback fail; encrypted-notebook or file-lock issues preventing tree updates; cascading failures after an invalid layout type plus a broken parent document.","solutions":["Read the wrapped root cause (%w chain) first and fix the original creation error","Check filesystem permissions/free space and workspace lock state to explain the cleanup failure","Manually inspect the parent document for orphaned database blocks and remove them if the cleanup left residue","Retry creation after fixing the environment; use errors.Is/As on the compound error to detect the root cause"],"exampleFix":"// before\nerr := fmt.Errorf(\"create failed: %v\", err) // losing chain\n// after\nif errors.Is(err, model.ErrWrongLayoutType) { /* handle root cause */ }\nvar cleanupErr error\n_ = errors.As(err, &cleanupErr) // inspect both create and cleanup failures via %w wrapping","handlingStrategy":"try-catch","validationCode":"// preflight: ensure parent exists and workspace is writable\nif err := treenode.CheckContainerParent(parentID); err != nil { return err }","typeGuard":null,"tryCatchPattern":"_, err := model.CreateAttributeViewDatabase(...)\nif err != nil {\n    var root error\n    if errors.As(err, &root) || errors.Unwrap(err) != nil {\n        log.Printf(\"create failed (cleanup may also have failed): %v\", err)\n    }\n    // inspect wrapped cause with errors.Is for known sentinels\n}","preventionTips":["Ensure adequate disk space and write permissions in the workspace before creating databases","Fix the root creation error first — cleanup failures are secondary symptoms","After such a compound error, manually check the parent document for orphaned blocks"],"tags":["error-wrapping","cleanup","database"],"backgroundTag":"database-write-failed","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}