siyuan-note/siyuan · error
Please initialize the data repo key first in [Settings - Acc
Error message
Please initialize the data repo key first in [Settings - Account & Sync - Local Data Repo - Data repo key]
What it means
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.
Source
Thrown at kernel/model/repository.go:201
}
purgeCancelMu.Unlock()
}()
_, err = repo.Purge(cancelCtx, retentionIndexIDs...)
}
func cancelPurge() {
purgeCancelMu.Lock()
defer purgeCancelMu.Unlock()
if nil != purgeCancel {
purgeCancel()
purgeCancel = nil
}
}
func GetRepoFile(fileID string) (ret []byte, p string, err error) {
if 1 > len(Conf.Repo.Key) {
err = errors.New(Conf.Language(26))
return
}
repo, err := newRepository()
if err != nil {
return
}
file, err := repo.GetFile(fileID)
if err != nil {
return
}
ret, err = repo.OpenFile(file)
if err != nil {
return
}
ret, err = decryptRepoDataIfNeeded(ret, file.Path)View on GitHub (pinned to 251596fc0d)
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.
Example fix
// before
data, path, err := model.GetRepoFile(fileID)
// after
if len(model.Conf.Repo.Key) == 0 {
return errors.New("please initialize the data repo key in Settings first")
}
data, path, err := model.GetRepoFile(fileID) Defensive patterns
Strategy: validation
Validate before calling
if len(Conf.Repo.Key) < 1 {
return nil, "", errors.New("data repo key not initialized; set it up in Settings - Account & Sync")
}
data, path, err := model.GetRepoFile(fileID) Type guard
func hasRepoKey() bool {
return len(Conf.Repo.Key) > 0
} Prevention
- 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.
When it happens
Trigger: 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().
Common situations: 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.
Related errors
- Please unlock the encrypted notebook first
- prepare box conf [%s] failed: %w
- encrypted notebook key material is missing
- Cannot import a key backup while encrypted notebooks are ena
- 312
AI-assisted analysis of siyuan-note/siyuan@251596fc0d (2026-08-12).
Data as JSON: /api/errors/97cdb641d5485230.
Report an issue: GitHub.