siyuan-note/siyuan · error
Conf.Language(157)
Error message
Conf.Language(157)
What it means
ImportRepoKey decodes the supplied key from Base64; if decoding fails (characters outside the Base64 alphabet, bad padding) the key is not recognized and the function returns the localized 'The key is not recognized, please confirm that the copied key string is correct' error (Conf.Language(157)). It indicates the input is not valid Base64 rather than a wrong-length key.
Source
Thrown at kernel/model/repository.go:1096
func ImportRepoKey(base64Key string) (retKey string, err error) {
release := lockAssetSourceChange()
defer release()
if err = requireCompleteAssetDownloads(); err != nil {
return
}
util.PushMsg(Conf.Language(136), 3000)
retKey = gulu.Str.RemoveInvisible(base64Key)
retKey = strings.TrimSpace(retKey)
if 1 > len(retKey) {
err = errors.New(Conf.Language(142))
return
}
key, err := base64.StdEncoding.DecodeString(retKey)
if err != nil {
logging.LogErrorf("import data repo key failed: %s", err)
return "", errors.New(Conf.Language(157))
}
if 32 != len(key) {
return "", errors.New(Conf.Language(157))
}
if err = clearAssetDownloadState(); err != nil {
return
}
suspendLANSyncManager()
Conf.Repo.Key = key
Conf.Save()
logging.LogInfof("imported repo key [%x]", sha1.Sum(Conf.Repo.Key))
if err = os.RemoveAll(Conf.Repo.GetSaveDir()); err != nil {
return
}
if err = os.MkdirAll(Conf.Repo.GetSaveDir(), 0755); err != nil {
returnView on GitHub (pinned to 8641553a1f)
Solutions
- Re-copy the key exactly from Settings - About - Data repo key on the source instance and paste it without edits
- Remove any prefixes/suffixes, whitespace or invisible characters; keep only the Base64 body
- If the source is a script, base64-encode the 32-byte key correctly (std encoding) before sending
- Confirm the transport did not mangle it (avoid shell interpolation, use file-based payloads for non-ASCII-laden input)
Example fix
// before: key copied with surrounding text
fetchPost('/api/repo/importRepoKey', {key: 'Repo key: AbC1...'})
// after: clean Base64 only
const key = raw.split(':')[1].trim()
fetchPost('/api/repo/importRepoKey', {key}) Defensive patterns
Strategy: validation
Validate before calling
function isProbablyBase64Key(s) { return /^[A-Za-z0-9+/]+={0,2}$/.test(s.trim()) }
if (!isProbablyBase64Key(key)) throw new Error('key is not valid Base64')
await api.importRepoKey(key.trim()) Type guard
const isBase64 = (v) => typeof v === 'string' && /^[A-Za-z0-9+/]+={0,2}$/.test(v.trim()) Try / catch
try { await api.importRepoKey(key) } catch (e) { if (/key is not recognized/i.test(e.message)) showPasteKeyAgainDialog(); else throw e } Prevention
- Copy the key with a single-click copy button, not manual selection
- Strip labels, quotes and whitespace before submitting
- Never route the key through markdown/shell transformations
- Validate Base64 shape client-side first
When it happens
Trigger: POST /api/repo/importRepoKey with a key string containing invalid Base64 (spaces/newlines beyond trimming, HTML-escaped characters, truncated copy, quotes or labels like 'Key: ' pasted along).
Common situations: Manually copying the key and missing characters or picking up surrounding text; key passed through a transformation that corrupted it (markdown formatting, shell quoting); pasting a key from a different format (hex instead of Base64).
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- Conf.Language(142)
- symlink resolves into encrypted notebook [%s]
- get block failed: %s
- load tree failed: %s
- view not found
AI-assisted analysis of siyuan-note/siyuan@8641553a1f (2026-09-11).
Data as JSON: /api/errors/58d753d0325c4d5a.
Report an issue: GitHub.