{"record":{"id":"e60bd76a183b1f04","repo":"siyuan-note/siyuan","slug":"input-can-not-be-empty-storage","errorCode":null,"errorMessage":"Input can not be empty","messagePattern":"Input can not be empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/storage.go","lineNumber":206,"sourceCode":"\tU                 bool `json:\"u\"`\n\tDocTitle          bool `json:\"docTitle\"`\n\tCodeBlock         bool `json:\"codeBlock\"`\n\tMathBlock         bool `json:\"mathBlock\"`\n\tHtmlBlock         bool `json:\"htmlBlock\"`\n}\n\nvar criteriaLock = sync.Mutex{}\n\nfunc GetCriteria() (ret []*Criterion) {\n\tcriteriaLock.Lock()\n\tdefer criteriaLock.Unlock()\n\tret, _ = getCriteria()\n\treturn\n}\n\nfunc SetCriterion(criterion *Criterion) (err error) {\n\tif \"\" == criterion.Name {\n\t\treturn errors.New(Conf.Language(142))\n\t}\n\n\tcriteriaLock.Lock()\n\tdefer criteriaLock.Unlock()\n\n\tcriteria, err := getCriteria()\n\tif err != nil {\n\t\treturn\n\t}\n\n\tupdate := false\n\tfor i, c := range criteria {\n\t\tif c.Name == criterion.Name {\n\t\t\tcriteria[i] = criterion\n\t\t\tupdate = true\n\t\t\tbreak\n\t\t}\n\t}","sourceCodeStart":188,"sourceCodeEnd":224,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/storage.go#L188-L224","documentation":"SetCriterion persists a named saved-search criterion. Before acquiring the criteria lock it requires criterion.Name to be a non-empty string; when the name is empty it returns the localized 'Input can not be empty' message (Conf.Language(142)). Criteria are keyed by name, so an empty name would be unusable and ambiguous.","triggerScenarios":"Calling kernel API /api/storage/setCriterion with a Criterion object whose Name field is \"\" or missing; frontend saving a search query without the user entering a name.","commonSituations":"A plugin automates criterion saving and leaves Name unset; UI dialog submitted without validation; a refactored struct field renamed so Name no longer populated.","solutions":["Set criterion.Name to a non-empty string before calling SetCriterion","In the caller UI, require the user to enter a name and block submission while empty","Generate a default name (e.g. timestamped) when the user omits one"],"exampleFix":"// before\nmodel.SetCriterion(&Criterion{})\n// after\nmodel.SetCriterion(&Criterion{Name: \"My saved search\", Criterion: ...})","handlingStrategy":"validation","validationCode":"if (!criterion || !criterion.Name || !criterion.Name.trim()) {\n  throw new Error(\"Criterion name is required\");\n}","typeGuard":"function hasName(c) { return typeof c?.Name === \"string\" && c.Name.length > 0; }","tryCatchPattern":null,"preventionTips":["Require the user to name a saved search before saving","Default to a generated name when input is empty","Validate form fields client-side before calling /api/storage/setCriterion"],"tags":["go","validation","empty-string","search-criteria"],"backgroundTag":"empty-required-field","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"}