{"record":{"id":"58d753d0325c4d5a","repo":"siyuan-note/siyuan","slug":"conf-language-157","errorCode":null,"errorMessage":"Conf.Language(157)","messagePattern":"Conf\\.Language\\(157\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/repository.go","lineNumber":1097,"sourceCode":"func ImportRepoKey(base64Key string) (retKey string, err error) {\n\trelease := lockAssetSourceChange()\n\tdefer release()\n\tif err = requireCompleteAssetDownloads(); err != nil {\n\t\treturn\n\t}\n\tutil.PushMsg(Conf.Language(136), 3000)\n\n\tretKey = gulu.Str.RemoveInvisible(base64Key)\n\tretKey = strings.TrimSpace(retKey)\n\tif 1 > len(retKey) {\n\t\terr = errors.New(Conf.Language(142))\n\t\treturn\n\t}\n\n\tkey, err := base64.StdEncoding.DecodeString(retKey)\n\tif err != nil {\n\t\tlogging.LogErrorf(\"import data repo key failed: %s\", err)\n\t\treturn \"\", errors.New(Conf.Language(157))\n\t}\n\tif 32 != len(key) {\n\t\treturn \"\", errors.New(Conf.Language(157))\n\t}\n\tif err = clearAssetDownloadState(); err != nil {\n\t\treturn\n\t}\n\n\tsuspendLANSyncManager()\n\tConf.Repo.Key = key\n\tConf.Save()\n\tlogging.LogInfof(\"imported repo key [%x]\", sha1.Sum(Conf.Repo.Key))\n\n\tif err = os.RemoveAll(Conf.Repo.GetSaveDir()); err != nil {\n\t\treturn\n\t}\n\tif err = os.MkdirAll(Conf.Repo.GetSaveDir(), 0755); err != nil {\n\t\treturn","sourceCodeStart":1079,"sourceCodeEnd":1115,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/repository.go#L1079-L1115","documentation":"ImportRepoKey decodes the supplied base64 key and validates it. If base64 decoding fails it logs the underlying error and returns localized error 157, meaning the string is not valid base64 and cannot be a repo key.","triggerScenarios":"ImportRepoKey called with a string that fails base64.StdEncoding.DecodeString (invalid characters, wrong padding, URL-safe alphabet instead of standard).","commonSituations":"Key copied with line breaks or HTML-escaped characters; key re-typed by hand; pasting a passphrase instead of the exported base64 key.","solutions":["Re-copy the exact base64 key from the exporting device without manual edits","Strip whitespace/line breaks from the pasted key before importing","Verify the string decodes: run base64.StdEncoding.DecodeString on it first"],"exampleFix":"// before\nmodel.ImportRepoKey(pastedKey)\n// after\nclean := strings.TrimSpace(strings.ReplaceAll(pastedKey, \"\\n\", \"\"))\nif _, err := base64.StdEncoding.DecodeString(clean); err != nil {\n    return errors.New(\"not a valid base64 repo key\")\n}\nmodel.ImportRepoKey(clean)","handlingStrategy":"validation","validationCode":"clean := strings.Join(strings.Fields(input), \"\")\nif _, err := base64.StdEncoding.DecodeString(clean); err != nil {\n    return errors.New(\"key is not valid standard base64\")\n}\nmodel.ImportRepoKey(clean)","typeGuard":null,"tryCatchPattern":"if err := model.ImportRepoKey(input); err != nil {\n    // show 'invalid key format' and let the user re-paste\n    return err\n}","preventionTips":["Copy keys as-is; never retype them by hand","Remove line breaks and HTML artifacts from pasted keys","Use standard (not URL-safe) base64 when exporting keys"],"tags":["repo","base64","validation"],"backgroundTag":"invalid-argument-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"}