siyuan-note/siyuan · error

Conf.Language(142)

Error message

Conf.Language(142)

What it means

SetCriterion saves a search/query criterion (saved filter) into storage/Storage/criteria.json. It refuses to persist a criterion whose Name field is the empty string, returning localized message 142 to tell the user a name is required. Criterion names are used as the identity for update-vs-insert, so an unnamed criterion could never be retrieved or updated.

Solutions

  1. Populate criterion.Name with a non-empty string before calling SetCriterion.
  2. In the UI, disable the save action or validate the name input is non-empty before submitting.
  3. If Name came from a deserialized payload, check the field mapping so the name is not silently dropped.

Example fix

// before
criterion := &model.Criterion{Name: ""}
model.SetCriterion(criterion)
// after
if criterion.Name == "" {
    criterion.Name = "My saved search"
}
model.SetCriterion(criterion)
Defensive patterns

Strategy: validation

Validate before calling

function canSetCriterion(criterion) {
  return typeof criterion?.Name === "string" && criterion.Name.trim().length > 0;
}

Type guard

function hasName(c) { return typeof c?.Name === "string" && c.Name.trim() !== ""; }

Try / catch

try {
  await fetchPost("/api/storage/setCriterion", { criterion });
} catch (e) {
  // message 142: prompt the user to enter a criterion name
  showMessage("Please enter a name for the criterion");
}

Prevention

When it happens

Trigger: Calling /api/storage/setCriterion (or model.SetCriterion) with a Criterion object whose Name is "" — e.g. the frontend saves a query without the user typing a name, or a plugin constructs a Criterion programmatically and leaves Name unset.

Common situations: User clicks 'Save criterion' in the search panel dialog without entering a name; automated scripts or plugins exporting/importing saved searches omitting the name field after a schema change.

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@8641553a1f (2026-09-11). Data as JSON: /api/errors/c1dc5b227b139a89. Report an issue: GitHub.

Appendix: source

Thrown at kernel/model/storage.go:202

	U                 bool `json:"u"`
	DocTitle          bool `json:"docTitle"`
	CodeBlock         bool `json:"codeBlock"`
	MathBlock         bool `json:"mathBlock"`
	HtmlBlock         bool `json:"htmlBlock"`
}

var criteriaLock = sync.Mutex{}

func GetCriteria() (ret []*Criterion) {
	criteriaLock.Lock()
	defer criteriaLock.Unlock()
	ret, _ = getCriteria()
	return
}

func SetCriterion(criterion *Criterion) (err error) {
	if "" == criterion.Name {
		return errors.New(Conf.Language(142))
	}

	criteriaLock.Lock()
	defer criteriaLock.Unlock()

	criteria, err := getCriteria()
	if err != nil {
		return
	}

	update := false
	for i, c := range criteria {
		if c.Name == criterion.Name {
			criteria[i] = criterion
			update = true
			break
		}
	}

View on GitHub (pinned to 8641553a1f)