siyuan-note/siyuan · error

Conf.Language(157)

Error message

Conf.Language(157)

What it means

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.

Solutions

  1. Re-copy the exact base64 key from the exporting device without manual edits
  2. Strip whitespace/line breaks from the pasted key before importing
  3. Verify the string decodes: run base64.StdEncoding.DecodeString on it first

Example fix

// before
model.ImportRepoKey(pastedKey)
// after
clean := strings.TrimSpace(strings.ReplaceAll(pastedKey, "\n", ""))
if _, err := base64.StdEncoding.DecodeString(clean); err != nil {
    return errors.New("not a valid base64 repo key")
}
model.ImportRepoKey(clean)
Defensive patterns

Strategy: validation

Validate before calling

clean := strings.Join(strings.Fields(input), "")
if _, err := base64.StdEncoding.DecodeString(clean); err != nil {
    return errors.New("key is not valid standard base64")
}
model.ImportRepoKey(clean)

Try / catch

if err := model.ImportRepoKey(input); err != nil {
    // show 'invalid key format' and let the user re-paste
    return err
}

Prevention

When it happens

Trigger: ImportRepoKey called with a string that fails base64.StdEncoding.DecodeString (invalid characters, wrong padding, URL-safe alphabet instead of standard).

Common situations: Key copied with line breaks or HTML-escaped characters; key re-typed by hand; pasting a passphrase instead of the exported base64 key.

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


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/58d753d0325c4d5a. Report an issue: GitHub.

Appendix: source

Thrown at kernel/model/repository.go:1097

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 {
		return

View on GitHub (pinned to 9f775e8a12)