siyuan-note/siyuan · error

; cleanup failed

Error message

%w; cleanup failed: %v

What it means

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.

Solutions

  1. Read the wrapped root cause (%w chain) first and fix the original creation error
  2. Check filesystem permissions/free space and workspace lock state to explain the cleanup failure
  3. Manually inspect the parent document for orphaned database blocks and remove them if the cleanup left residue
  4. Retry creation after fixing the environment; use errors.Is/As on the compound error to detect the root cause

Example fix

// before
err := fmt.Errorf("create failed: %v", err) // losing chain
// after
if errors.Is(err, model.ErrWrongLayoutType) { /* handle root cause */ }
var cleanupErr error
_ = errors.As(err, &cleanupErr) // inspect both create and cleanup failures via %w wrapping
Defensive patterns

Strategy: try-catch

Validate before calling

// preflight: ensure parent exists and workspace is writable
if err := treenode.CheckContainerParent(parentID); err != nil { return err }

Try / catch

_, err := model.CreateAttributeViewDatabase(...)
if err != nil {
    var root error
    if errors.As(err, &root) || errors.Unwrap(err) != nil {
        log.Printf("create failed (cleanup may also have failed): %v", err)
    }
    // inspect wrapped cause with errors.Is for known sentinels
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/6cee872a00898f6b. Report an issue: GitHub.

Appendix: source

Thrown at kernel/model/attribute_view_create.go:245

}

func cleanupCreatedAttributeView(blockID, avID string) (err error) {
	if "" != blockID {
		err = PerformTxSync(&Transaction{DoOperations: []*Operation{{Action: "delete", ID: blockID}}})
	}
	avJSONPath, boxID := av.FindAttributeViewPath(avID)
	if "" != avJSONPath && filelock.IsExist(avJSONPath) {
		err = errors.Join(err, filelock.RemoveWithoutFatal(avJSONPath))
	}
	cache.RemoveAVDataInBox(avID, boxID)
	return
}

func databaseCreationError(createErr, cleanupErr error) error {
	if nil == cleanupErr {
		return createErr
	}
	return fmt.Errorf("%w; cleanup failed: %v", createErr, cleanupErr)
}

View on GitHub (pinned to 9f775e8a12)