{"record":{"id":"9b7d0dae7e4d9ad2","repo":"siyuan-note/siyuan","slug":"read-history-snapshot-s-failed-w","errorCode":null,"errorMessage":"read history snapshot [%s] failed: %w","messagePattern":"read history snapshot \\[(.+?)\\] failed: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/crypto.go","lineNumber":803,"sourceCode":"}\n\nfunc encryptedNotebookHistoryBoxDirs() (ret []string, err error) {\n\tentries, err := os.ReadDir(util.HistoryDir)\n\tif err != nil {\n\t\tif os.IsNotExist(err) {\n\t\t\treturn nil, nil\n\t\t}\n\t\treturn nil, fmt.Errorf(\"read history dir failed: %w\", err)\n\t}\n\tfor _, entry := range entries {\n\t\tif !entry.IsDir() {\n\t\t\tcontinue\n\t\t}\n\t\t// 历史快照目录：<ts>-<op>，其下是各 boxID 子目录\n\t\tsnapshotDir := filepath.Join(util.HistoryDir, entry.Name())\n\t\tboxEntries, readErr := os.ReadDir(snapshotDir)\n\t\tif readErr != nil {\n\t\t\treturn nil, fmt.Errorf(\"read history snapshot [%s] failed: %w\", entry.Name(), readErr)\n\t\t}\n\t\tfor _, boxEntry := range boxEntries {\n\t\t\tif !boxEntry.IsDir() || !ast.IsNodeIDPattern(boxEntry.Name()) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tencrypted, checkErr := isEncryptedHistoryBoxDir(filepath.Join(snapshotDir, boxEntry.Name()))\n\t\t\tif checkErr != nil {\n\t\t\t\treturn nil, checkErr\n\t\t\t}\n\t\t\tif encrypted {\n\t\t\t\tret = append(ret, filepath.Join(snapshotDir, boxEntry.Name()))\n\t\t\t}\n\t\t}\n\t}\n\treturn ret, nil\n}\n\nfunc hasEncryptedNotebookDeleteHistory(boxID string) (bool, error) {","sourceCodeStart":785,"sourceCodeEnd":821,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/crypto.go#L785-L821","documentation":"While enumerating history snapshots, each <ts>-<op> snapshot directory under the history dir is read to find per-box (boxID) subdirectories. This error is thrown when one snapshot directory cannot be listed; unlike a missing top-level history dir, a single bad snapshot aborts the whole scan because it may hold encrypted recovery material whose presence must not be misjudged. The snapshot name and OS error are wrapped.","triggerScenarios":"os.ReadDir on a specific history/<ts>-<op> snapshot directory fails with a non-ENOENT-style fatal error during scanEncryptedNotebookHistory or verifyKEKAgainstEncryptedHistory — e.g. permission denied, I/O error, or the entry was replaced by something unreadable mid-scan.","commonSituations":"Partial deletion/cleanup of history left a corrupt snapshot entry; snapshot dir owned by another user after migration; Windows file lock from backup/indexing software; failing disk sector under the history tree.","solutions":["Check permissions/ownership of the named snapshot directory (<ts>-<op>) and fix read access","Identify and release whatever locks the directory (antivirus, backup, sync client) and retry","If the snapshot is provably corrupt and not needed for recovery, remove just that snapshot dir so the scan can proceed","Run filesystem checks (fsck/chkdsk) if the wrapped cause indicates I/O errors"],"exampleFix":"// before: scanning an unhealthy history tree directly\nboxes, err := encryptedNotebookHistoryBoxDirs()\n// after: probe each snapshot dir first and repair/flag the bad one\nfor _, name := range snapshotNames {\n    if _, err := os.ReadDir(filepath.Join(util.HistoryDir, name)); err != nil {\n        log.Printf(\"snapshot %s unreadable, excluding: %v\", name, err)\n    }\n}\nboxes, err = encryptedNotebookHistoryBoxDirs()","handlingStrategy":"try-catch","validationCode":"entries, _ := os.ReadDir(util.HistoryDir)\nfor _, e := range entries {\n    if _, err := os.ReadDir(filepath.Join(util.HistoryDir, e.Name())); err != nil {\n        // snapshot unreadable — repair or exclude before scanning\n    }\n}","typeGuard":"func snapshotReadable(snapshotDir string) bool {\n    f, err := os.Open(snapshotDir)\n    if err != nil { return false }\n    defer f.Close()\n    return true\n}","tryCatchPattern":"boxes, err := encryptedNotebookHistoryBoxDirs()\nif err != nil {\n    if strings.Contains(err.Error(), \"read history snapshot\") {\n        // quarantine the named snapshot and rescan\n    }\n    return err\n}","preventionTips":["Avoid interrupting history cleanup/deletion mid-run","Fix snapshot dir ownership after copying workspaces between users","Check disks showing I/O errors before running recovery","Never delete snapshot dirs while the kernel is running"],"tags":["filesystem","io","history","snapshot"],"backgroundTag":"file-read-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"}