{"record":{"id":"938b177cf623ddf1","repo":"siyuan-note/siyuan","slug":"invalid-deck-id","errorCode":null,"errorMessage":"invalid deck ID","messagePattern":"invalid deck ID","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/flashcard.go","lineNumber":1217,"sourceCode":"func RenameDeck(deckID, name string) (err error) {\n\tdeckLock.Lock()\n\tdefer deckLock.Unlock()\n\n\twaitForSyncingStorages()\n\n\tdeck := Decks[deckID]\n\tdeck.Name = name\n\terr = deck.Save()\n\tif err != nil {\n\t\tlogging.LogErrorf(\"save deck [%s] failed: %s\", deckID, err)\n\t\treturn\n\t}\n\treturn\n}\n\nfunc RemoveDeck(deckID string) (err error) {\n\tif !ast.IsNodeIDPattern(deckID) {\n\t\terr = errors.New(\"invalid deck ID\")\n\t\treturn\n\t}\n\n\tdeckLock.Lock()\n\tdefer deckLock.Unlock()\n\n\twaitForSyncingStorages()\n\n\triffSavePath := getRiffDir()\n\tdeckPath := filepath.Join(riffSavePath, deckID+\".deck\")\n\tif filelock.IsExist(deckPath) {\n\t\tif err = filelock.Remove(deckPath); err != nil {\n\t\t\treturn\n\t\t}\n\t}\n\n\tcardsPath := filepath.Join(riffSavePath, deckID+\".cards\")\n\tif filelock.IsExist(cardsPath) {","sourceCodeStart":1199,"sourceCodeEnd":1235,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/flashcard.go#L1199-L1235","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Pass the deck's real SiYuan node ID (the ID from ListDecks / the deck backing block), not a name or custom key","Validate the ID client-side with the same 20-character node-ID pattern before calling RemoveDeck","If the deck came from an external source, re-import or re-create it in SiYuan so it gets a proper node ID"],"exampleFix":"// before\nerr = model.RemoveDeck(deck.Name)\n// after\nif !isNodeIDPattern(deck.ID) {\n    return fmt.Errorf(\"refusing to remove deck with non-node ID %q\", deck.ID)\n}\nerr = model.RemoveDeck(deck.ID)","handlingStrategy":"validation","validationCode":"var nodeIDRe = regexp.MustCompile(`^[0-9a-z]{20}$`)\nif !nodeIDRe.MatchString(deckID) {\n    return errors.New(\"deck ID must be a 20-char SiYuan node ID\")\n}\nerr := model.RemoveDeck(deckID)","typeGuard":"func isNodeID(id string) bool { return ast.IsNodeIDPattern(id) }","tryCatchPattern":"if err := model.RemoveDeck(deckID); err != nil {\n    if strings.Contains(err.Error(), \"invalid deck ID\") {\n        return fmt.Errorf(\"deck %q is not a valid node ID; fetch it from ListDecks\", deckID)\n    }\n    return err\n}","preventionTips":["Always source deck IDs from ListDecks or the backing block, never from user input or external stores","Validate IDs against the node-ID pattern before destructive deck operations","Avoid string transformations (trimming, uppercasing) on stored IDs"],"tags":["flashcards","deck","validation"],"backgroundTag":"invalid-identifier-format","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"}