siyuan-note/siyuan · error

%w; cleanup failed: %v

Error message

%w; cleanup failed: %v

What it means

newItemCreationError is a helper that combines the original creation error with a follow-up cleanup error. When documents were partially created and then removal of those artifacts also fails, the returned error wraps the creation error (%w) and appends '; cleanup failed: <cleanup error>', so both failures are visible in one message.

Source

Thrown at kernel/model/attribute_view_new_item.go:683

}

func applyNewItemContentTemplate(templatePath, docID string) error {
	return applyDocContentTemplateAfterIndex(templatePath, docID)
}

func removeCreatedNewItemDoc(docID string) error {
	blockTree := treenode.GetBlockTree(docID)
	if nil == blockTree {
		return nil
	}
	return RemoveDoc(blockTree.BoxID, blockTree.Path)
}

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

View on GitHub (pinned to 8641553a1f)

Solutions

  1. Fix the root cause reported before '; cleanup failed:' — that is the error that aborted creation
  2. Manually inspect the notebook for orphaned documents created by the failed run and delete them
  3. Check data-directory write permissions and that no external process locks the .sy files
  4. Retry the operation after resolving both the create error and the cleanup error

Example fix

// reading the combined error
if err != nil {
    if strings.Contains(err.Error(), "; cleanup failed:") {
        parts := strings.SplitN(err.Error(), "; cleanup failed: ", 2)
        log.Printf("create error: %s; cleanup: %s", parts[0], parts[1])
    }
}
Defensive patterns

Strategy: try-catch

Validate before calling

// ensure preconditions so creation succeeds and cleanup is never triggered:
if err := validateTemplate(attrView, itemTemplate); err != nil {
    return err // fail fast before any document is created
}

Try / catch

err := model.CreateAttributeViewItemDocs(avID, itemIDs, cfg)
if err != nil {
    if idx := strings.Index(err.Error(), "; cleanup failed: "); idx >= 0 {
        createErr, cleanupErr := err.Error()[:idx], err.Error()[idx:]
        log.Printf("create: %s | cleanup: %s", createErr, cleanupErr)
        // manually remove orphaned documents listed in cleanup error
    }
    return err
}

Prevention

When it happens

Trigger: Any failure inside createAttributeViewItem, CreateAttributeViewItemDocs, or createAttributeViewItemDocumentWithMarkdown where cleanupCreatedDocs() (or equivalent cleanup) also returns non-nil — e.g. the original template resolution failed after some documents were already written, and deleting them hit a filesystem lock or permission problem.

Common situations: Document files locked by sync/antivirus while the kernel tries to remove them; permission issues in the data directory; cleanup invoked twice leaving orphaned files whose deletion fails; disk-full conditions during removal.

Related errors


AI-assisted analysis of siyuan-note/siyuan@8641553a1f (2026-09-11). Data as JSON: /api/errors/63a75b2d734cb466. Report an issue: GitHub.