{"record":{"id":"566bca046c4b022a","repo":"siyuan-note/siyuan","slug":"title-is-required","errorCode":null,"errorMessage":"--title is required","messagePattern":"--title is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/cli/cmd/document.go","lineNumber":80,"sourceCode":"\t\t\tprintDocumentTable(files)\n\t\t}\n\t\treturn nil\n\t},\n}\n\nvar documentCreateCmd = &cobra.Command{\n\tUse:   \"create --notebook <id> --title <title>\",\n\tShort: \"Create a document\",\n\tRunE: func(cmd *cobra.Command, args []string) error {\n\t\tnotebook, _ := cmd.Flags().GetString(\"notebook\")\n\t\ttitle, _ := cmd.Flags().GetString(\"title\")\n\t\tdir, _ := cmd.Flags().GetString(\"path\")\n\t\tmarkdown, _ := cmd.Flags().GetString(\"markdown\")\n\t\tif notebook == \"\" {\n\t\t\treturn fmt.Errorf(\"--notebook is required\")\n\t\t}\n\t\tif title == \"\" {\n\t\t\treturn fmt.Errorf(\"--title is required\")\n\t\t}\n\t\tdir = normalizeDocumentCreateParentPath(dir)\n\t\tid := ast.NewNodeID()\n\t\tdocPath := path.Join(dir, id+\".sy\")\n\t\tif err := model.ValidateCreateDoc(notebook, docPath, title); err != nil {\n\t\t\treturn formatNotebookWriteError(notebook, err)\n\t\t}\n\n\t\tif dryRun {\n\t\t\tfmt.Printf(\"[dry-run] Would create document \\\"%s\\\" in notebook %s\\n\", title, notebook)\n\t\t\treturn nil\n\t\t}\n\n\t\t_, err := model.CreateDocByMd(notebook, docPath, title, markdown, nil, nil)\n\t\tif err != nil {\n\t\t\treturn formatNotebookWriteError(notebook, err)\n\t\t}\n\t\tmodel.AppendPushCreateEntry(notebook, docPath)","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/cli/cmd/document.go#L62-L98","documentation":"After the notebook check, `siyuan document create` validates that a non-empty title was supplied via `--title`. The title is used for model.ValidateCreateDoc and for the new document, so an empty title is rejected with this error before any file is written.","triggerScenarios":"Running `siyuan document create --notebook <notebookID>` without `--title`, or with `--title \"\"`. Also when a TITLE shell variable is empty due to a failed upstream substitution.","commonSituations":"Batch-creation scripts reading titles from a data file where a row's title column is empty; forgetting --title while testing the command interactively; passing the title through a variable that was never set.","solutions":["Pass a non-empty title: `siyuan document create --notebook <notebookID> --title \"My document\"`","Check the source data/variable so empty titles are skipped or defaulted before invoking","If the title is intentionally empty, supply a placeholder since the kernel requires one"],"exampleFix":"// before\nsiyuan document create --notebook $NB_ID\n// after\nsiyuan document create --notebook $NB_ID --title \"Untitled\"","handlingStrategy":"validation","validationCode":"[ -n \"$TITLE\" ] || { echo \"--title is required\" >&2; exit 1; }\nsiyuan document create --notebook \"$NB_ID\" --title \"$TITLE\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Trim/validate titles read from data files before batch creation","Default to a placeholder title when source data is empty","Test create commands interactively with all flags before scripting them"],"tags":["cli","validation","document","missing-flag"],"backgroundTag":"missing-required-flag","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"}