siyuan-note/siyuan · warning

Input can not be empty

Error message

Input can not be empty

What it means

ImportRepoKey: after removing invisible chars and trimming whitespace, the base64 key string is empty. The function refuses with i18n key 142 ('Input can not be empty') before attempting any decode. This is a pure input-validation guard.

Source

Thrown at kernel/model/repository.go:1095

		for _, tc := range ret[10:] {
			tc.Count += otherCount
		}
		other := &TypeCount{
			Type:  "Other",
			Count: otherCount,
		}
		ret = append(ret[:10], other)
	}
	return
}

func ImportRepoKey(base64Key string) (retKey string, err error) {
	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))
	}

	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 {

View on GitHub (pinned to 251596fc0d)

Solutions

  1. Provide a non-empty base64 repo key string exported from a prior 'export data repo key' operation.
  2. Trim and validate the input on the caller side before calling ImportRepoKey.

Example fix

// before
ImportRepoKey("")
// after
if strings.TrimSpace(key) == "" { return errors.New("key required") }
ImportRepoKey(key)
Defensive patterns

Strategy: validation

Validate before calling

cleaned := strings.TrimSpace(gulu.Str.RemoveInvisible(base64Key))
if len(cleaned) == 0 {
    return "", errors.New(model.Conf.Language(142))
}

Prevention

When it happens

Trigger: Calling ImportRepoKey with an empty string, whitespace-only string, or a string consisting solely of invisible/zero-width characters.

Common situations: Frontend sent an empty form field; clipboard paste of whitespace; programmatic caller passed an unset variable.

Related errors


AI-assisted analysis of siyuan-note/siyuan@251596fc0d (2026-08-12). Data as JSON: /api/errors/4117c031e12b43df. Report an issue: GitHub.