{"record":{"id":"7f69f1bf09d927d6","repo":"siyuan-note/siyuan","slug":"106","errorCode":"106","errorMessage":"Maximum length is limited to 512 characters","messagePattern":"Maximum length is limited to 512 characters","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/mount.go","lineNumber":68,"sourceCode":"func getOpenedBox(boxID string) (ret *Box, err error) {\n\tif ret = Conf.Box(boxID); nil != ret {\n\t\treturn\n\t}\n\tif nil != Conf.GetBox(boxID) {\n\t\treturn nil, ErrBoxClosed\n\t}\n\treturn nil, ErrBoxNotFound\n}\n\nfunc CreateBox(name string) (id string, err error) {\n\treturn createBox(name, true)\n}\n\nfunc createBox(name string, initializeBoxDoc bool) (id string, err error) {\n\tname = normalizeBoxName(name)\n\tif 512 < utf8.RuneCountInString(name) {\n\t\t// 限制笔记本名和文档名最大长度为 `512` https://github.com/siyuan-note/siyuan/issues/6299\n\t\terr = errors.New(Conf.Language(106))\n\t\treturn\n\t}\n\tFlushTxQueue()\n\n\tcreateDocLock.Lock()\n\tdefer createDocLock.Unlock()\n\n\tboxes, _ := ListNotebooks()\n\tfor i, b := range boxes {\n\t\tc := b.GetConf()\n\t\tc.Sort = i + 1\n\t\tif err := b.SaveConf(c); err != nil {\n\t\t\tlogging.LogErrorf(\"save box conf [%s] failed: %s\", b.ID, err)\n\t\t}\n\t}\n\n\tid = ast.NewNodeID()\n\tboxLocalPath := filepath.Join(util.DataDir, id)","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/251596fc0de2f9528c00c224252fd073a99973f4/kernel/model/mount.go#L50-L86","documentation":"In createBox (the body behind CreateBox), if utf8.RuneCountInString(name) > 512 the function returns errors.New(Conf.Language(106)) = 'Maximum length is limited to 512 characters'. The limit is by Unicode rune count, not byte count, and applies after normalizeBoxName. Reference: siyuan-note/siyuan#6299.","triggerScenarios":"Calling CreateBox (or any internal path through createBox) with a name longer than 512 runes. This is the notebook-creation API; the same 512-rune ceiling is enforced on RenameBox (796) and document titles elsewhere.","commonSituations":"Programmatic creation with an unbounded user input (e.g. importing a folder name as a notebook); paste of a very long string; a script that derives the notebook name from a long path or metadata field.","solutions":["Truncate or prompt for a shorter name before calling CreateBox: keep to ≤512 Unicode code points.","Validate with utf8.RuneCountInString(name) <= 512 in your caller and surface a friendly error.","Strip excessive whitespace/normalise via the same logic the kernel uses if you want to maximise usable length."],"exampleFix":"// before\nname := longExternalString\nid, err := model.CreateBox(name) // err == Language(106)\n\n// after\nconst maxNameRunes = 512\nif utf8.RuneCountInString(name) > maxNameRunes {\n    name = string([]rune(name)[:maxNameRunes])\n}\nid, err := model.CreateBox(name)","handlingStrategy":"validation","validationCode":"const maxNotebookNameRunes = 512\nfunc validNotebookName(name string) error {\n    if utf8.RuneCountInString(name) > maxNotebookNameRunes {\n        return fmt.Errorf(\"name exceeds %d runes\", maxNotebookNameRunes)\n    }\n    return nil\n}","typeGuard":"null","tryCatchPattern":"null","preventionTips":["Clamp user input to ≤512 runes before CreateBox/RenameBox.","Validate at the UI/API boundary, not just at the kernel call."],"tags":["notebook","mount","validation","length-limit"],"backgroundTag":null,"analyzedSha":"251596fc0de2f9528c00c224252fd073a99973f4","analyzedAt":"2026-08-12T21:18:37.123Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}