{"record":{"id":"97cdb641d5485230","repo":"siyuan-note/siyuan","slug":"please-initialize-the-data-repo-key-first-in-sett","errorCode":null,"errorMessage":"Please initialize the data repo key first in [Settings - Account & Sync - Local Data Repo - Data repo key]","messagePattern":"Please initialize the data repo key first in \\[Settings - Account & Sync - Local Data Repo - Data repo key\\]","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/repository.go","lineNumber":201,"sourceCode":"\t\t}\n\t\tpurgeCancelMu.Unlock()\n\t}()\n\n\t_, err = repo.Purge(cancelCtx, retentionIndexIDs...)\n}\n\nfunc cancelPurge() {\n\tpurgeCancelMu.Lock()\n\tdefer purgeCancelMu.Unlock()\n\tif nil != purgeCancel {\n\t\tpurgeCancel()\n\t\tpurgeCancel = nil\n\t}\n}\n\nfunc GetRepoFile(fileID string) (ret []byte, p string, err error) {\n\tif 1 > len(Conf.Repo.Key) {\n\t\terr = errors.New(Conf.Language(26))\n\t\treturn\n\t}\n\n\trepo, err := newRepository()\n\tif err != nil {\n\t\treturn\n\t}\n\n\tfile, err := repo.GetFile(fileID)\n\tif err != nil {\n\t\treturn\n\t}\n\n\tret, err = repo.OpenFile(file)\n\tif err != nil {\n\t\treturn\n\t}\n\tret, err = decryptRepoDataIfNeeded(ret, file.Path)","sourceCodeStart":183,"sourceCodeEnd":219,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/251596fc0de2f9528c00c224252fd073a99973f4/kernel/model/repository.go#L183-L219","documentation":"Thrown by GetRepoFile() via Conf.Language(26) which resolves to 'Please initialize the data repo key first in [Settings - Account & Sync - Local Data Repo - Data repo key]'. The data repo uses dejavu encryption; all file retrieval requires the repo key to decrypt snapshot data. If Conf.Repo.Key is empty (len < 1), the function refuses immediately before attempting any repository operation.","triggerScenarios":"Calling GetRepoFile(fileID) when Conf.Repo.Key has not been initialized (len(Conf.Repo.Key) < 1). This occurs when the user has never created a data repo key, or the key was lost/reset. The guard fires before newRepository() or repo.GetFile().","commonSituations":"A fresh SiYuan installation where the user has not yet gone through data repo key initialization. The user is trying to access a file from a data repo snapshot via the history/file browser without having set up the encryption key. The conf.json was reset or migrated and the key reference was lost.","solutions":["Navigate to Settings - Account & Sync - Local Data Repo - Data repo key and create/init the key.","If the key was previously created but lost, use the recovery/import key flow if available; otherwise a new key means previous encrypted snapshots cannot be decrypted.","In the calling code, check len(Conf.Repo.Key) > 0 before calling GetRepoFile and prompt the user to set up the key."],"exampleFix":"// before\ndata, path, err := model.GetRepoFile(fileID)\n\n// after\nif len(model.Conf.Repo.Key) == 0 {\n    return errors.New(\"please initialize the data repo key in Settings first\")\n}\ndata, path, err := model.GetRepoFile(fileID)","handlingStrategy":"validation","validationCode":"if len(Conf.Repo.Key) < 1 {\n    return nil, \"\", errors.New(\"data repo key not initialized; set it up in Settings - Account & Sync\")\n}\ndata, path, err := model.GetRepoFile(fileID)","typeGuard":"func hasRepoKey() bool {\n    return len(Conf.Repo.Key) > 0\n}","tryCatchPattern":null,"preventionTips":["Initialize the data repo key immediately after first workspace setup.","Gate UI actions that call GetRepoFile on hasRepoKey().","Show a setup wizard for the data repo key on first use."],"tags":["data-repo","encryption","config","guard","dejavu"],"backgroundTag":null,"analyzedSha":"251596fc0de2f9528c00c224252fd073a99973f4","analyzedAt":"2026-08-12T21:18:37.123Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}