siyuan-note/siyuan · error

invalid deck ID

Error message

invalid deck ID

What it means

RemoveDeck validates that the deck ID looks like a SiYuan node ID (ast.IsNodeIDPattern: 20-char lowercase base32-style ID) before deleting. Deck IDs are the IDs of the blocks/documents backing the deck; anything else — empty string, a numeric ID, a UUID — is rejected as "invalid deck ID" without touching the store.

Solutions

  1. Pass the deck's real SiYuan node ID (the ID from ListDecks / the deck backing block), not a name or custom key
  2. Validate the ID client-side with the same 20-character node-ID pattern before calling RemoveDeck
  3. If the deck came from an external source, re-import or re-create it in SiYuan so it gets a proper node ID

Example fix

// before
err = model.RemoveDeck(deck.Name)
// after
if !isNodeIDPattern(deck.ID) {
    return fmt.Errorf("refusing to remove deck with non-node ID %q", deck.ID)
}
err = model.RemoveDeck(deck.ID)
Defensive patterns

Strategy: validation

Validate before calling

var nodeIDRe = regexp.MustCompile(`^[0-9a-z]{20}$`)
if !nodeIDRe.MatchString(deckID) {
    return errors.New("deck ID must be a 20-char SiYuan node ID")
}
err := model.RemoveDeck(deckID)

Type guard

func isNodeID(id string) bool { return ast.IsNodeIDPattern(id) }

Try / catch

if err := model.RemoveDeck(deckID); err != nil {
    if strings.Contains(err.Error(), "invalid deck ID") {
        return fmt.Errorf("deck %q is not a valid node ID; fetch it from ListDecks", deckID)
    }
    return err
}

Prevention

When it happens

Trigger: Calling model.RemoveDeck(deckID) with an ID that does not match the node-ID pattern: empty string, a deck name, a SQL rowid, or a truncated/uppercase ID. This happens before the deck lock is taken.

Common situations: Plugin code stored its own identifier for decks and passes it to RemoveDeck; data migrated from another tool has non-SiYuan IDs; a string was trimmed/sliced and corrupted the ID.

Understand the failure class

Background: "invalid id" errors: invalid identifier format — why libraries reject IDs before lookup, and how to fix them — this error's family across 37 libraries.

Related errors


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

Appendix: source

Thrown at kernel/model/flashcard.go:1217

func RenameDeck(deckID, name string) (err error) {
	deckLock.Lock()
	defer deckLock.Unlock()

	waitForSyncingStorages()

	deck := Decks[deckID]
	deck.Name = name
	err = deck.Save()
	if err != nil {
		logging.LogErrorf("save deck [%s] failed: %s", deckID, err)
		return
	}
	return
}

func RemoveDeck(deckID string) (err error) {
	if !ast.IsNodeIDPattern(deckID) {
		err = errors.New("invalid deck ID")
		return
	}

	deckLock.Lock()
	defer deckLock.Unlock()

	waitForSyncingStorages()

	riffSavePath := getRiffDir()
	deckPath := filepath.Join(riffSavePath, deckID+".deck")
	if filelock.IsExist(deckPath) {
		if err = filelock.Remove(deckPath); err != nil {
			return
		}
	}

	cardsPath := filepath.Join(riffSavePath, deckID+".cards")
	if filelock.IsExist(cardsPath) {

View on GitHub (pinned to 9f775e8a12)