siyuan-note/siyuan · error

Conf.Language(142)

Error message

Conf.Language(142)

What it means

ImportRepoKey imports an existing data repo key from a base64 string. Before decoding it strips invisible characters and whitespace; if nothing remains it returns localized error 142, indicating the provided key string is empty.

Solutions

  1. Provide a non-empty base64-encoded 32-byte repo key string
  2. Copy the key again from the source device and retry the import
  3. Guard the call by trimming and length-checking the input before invoking

Example fix

// before
model.ImportRepoKey(userInput)
// after
trimmed := strings.TrimSpace(userInput)
if trimmed == "" {
    return errors.New("repo key is required")
}
model.ImportRepoKey(trimmed)
Defensive patterns

Strategy: validation

Validate before calling

key := strings.TrimSpace(gulu.Str.RemoveInvisible(input))
if key == "" {
    return errors.New("repo key must not be empty")
}
model.ImportRepoKey(key)

Try / catch

if _, err := model.ImportRepoKey(input); err != nil {
    return fmt.Errorf("import repo key: %w", err)
}

Prevention

When it happens

Trigger: Calling ImportRepoKey with a base64 key that is empty or consists only of whitespace/invisible characters after trimming.

Common situations: User pasted an empty clipboard; input field left blank in the import-key dialog; copying failed so only invisible characters were transferred.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


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

Appendix: source

Thrown at kernel/model/repository.go:1090

			Count: otherCount,
		}
		ret = append(ret[:10], other)
	}
	return
}

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()

View on GitHub (pinned to 9f775e8a12)