{"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":76,"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":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/251596fc0de2f9528c00c224252fd073a99973f4/kernel/cli/cmd/document.go#L58-L94","documentation":"The `document create` subcommand requires --title in addition to --notebook. The handler checks notebook first, then title, returning this error when title is empty. The title is used as the document's display name and feeds into ValidateCreateDoc, so an empty title would produce an invalid document. The --path and --markdown flags remain optional.","triggerScenarios":"Running `siyuan document create --notebook <id>` without --title; passing `--title \"\"`; scripting where the title variable is empty for an iteration; using --markdown in the hope it derives a title automatically.","commonSituations":"Expecting the title to default to the first heading of --markdown content; passing an empty title intending to rename later; shell quoting that collapses the title to empty; copy-paste leaving a placeholder.","solutions":["Provide a non-empty title: `siyuan document create --notebook <id> --title \"My Doc\"`.","If the title comes from markdown content, extract it in the script and pass it explicitly.","Guard the title variable in scripts before invoking.","Confirm the flag with `siyuan document create --help`."],"exampleFix":"// before\nsiyuan document create --notebook 20240101000000-xyz --markdown '# Hello'\n// after\nsiyuan document create --notebook 20240101000000-xyz --title \"Hello\" --markdown '# Hello'","handlingStrategy":"validation","validationCode":"[ -n \"$TITLE\" ] || { echo '--title is required' >&2; exit 2; }\nsiyuan document create --notebook \"$NOTEBOOK\" --title \"$TITLE\"","typeGuard":null,"tryCatchPattern":"if ! siyuan document create --notebook \"$NOTEBOOK\" --title \"$TITLE\" 2>err.txt; then\n  grep -q 'title is required' err.txt && echo \"pass a non-empty --title\" >&2\n  exit 1\nfi","preventionTips":["Derive the title explicitly from markdown content if needed, do not assume a default.","Trim and assert non-empty in scripts.","Use `set -u`."],"tags":["cli","cobra","flag-validation","document","go"],"backgroundTag":null,"analyzedSha":"251596fc0de2f9528c00c224252fd073a99973f4","analyzedAt":"2026-08-12T21:18:37.123Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}