{"record":{"id":"b7be57416b6110a1","repo":"siyuan-note/siyuan","slug":"path-is-required-b7be57","errorCode":null,"errorMessage":"--path is required","messagePattern":"--path is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/cli/cmd/file.go","lineNumber":283,"sourceCode":"\tif err != nil {\n\t\treturn err\n\t}\n\tdefer dstF.Close()\n\t_, err = io.Copy(dstF, srcF)\n\treturn err\n}\n\nvar fileGrepCmd = &cobra.Command{\n\tUse:   \"grep --pattern <regex> --path <path>\",\n\tShort: \"Search file contents with regex\",\n\tRunE: func(cmd *cobra.Command, args []string) error {\n\t\tpattern, _ := cmd.Flags().GetString(\"pattern\")\n\t\tif pattern == \"\" {\n\t\t\treturn fmt.Errorf(\"--pattern is required\")\n\t\t}\n\t\trelPath, _ := cmd.Flags().GetString(\"path\")\n\t\tif relPath == \"\" {\n\t\t\treturn fmt.Errorf(\"--path is required\")\n\t\t}\n\t\tabs, err := absPath(relPath)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tinclude, _ := cmd.Flags().GetString(\"include\")\n\t\tctx, _ := cmd.Flags().GetInt(\"context\")\n\t\tmax, _ := cmd.Flags().GetInt(\"limit\")\n\t\tif max <= 0 {\n\t\t\tmax = 200\n\t\t}\n\t\tresults, err := gulu.File.Grep(abs, include, pattern, ctx, max)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tswitch outputFormat {\n\t\tcase \"json\":\n\t\t\tdata, _ := json.MarshalIndent(results, \"\", \"  \")","sourceCodeStart":265,"sourceCodeEnd":301,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/251596fc0de2f9528c00c224252fd073a99973f4/kernel/cli/cmd/file.go#L265-L301","documentation":"Thrown by the `file grep` subcommand when the `--path` flag is empty. The path scopes the regex search to a workspace-relative directory; without it the search root is undefined. This check runs after the `--pattern` check, so both must pass.","triggerScenarios":"Running `siyuan file grep --pattern \"TODO\"` with no `--path`, or `--path` set to an empty string. The flag is read and validated before `absPath` is called.","commonSituations":"Assuming grep defaults to the whole workspace (it does not); omitting `--path` while copying a pattern from elsewhere; an unexpanded env var for the path.","solutions":["Add the search root: `siyuan file grep --pattern \"TODO\" --path data/`","Use `.` or `data/` to scope to the workspace data directory"],"exampleFix":"// before\nsiyuan file grep --pattern \"TODO\"\n// after\nsiyuan file grep --pattern \"TODO\" --path data/","handlingStrategy":"validation","validationCode":"if path == \"\" {\n    return errors.New(\"a workspace-relative search path is required\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pair `--pattern` with `--path` for `file grep`","Scope searches to a subdirectory to keep results manageable","Remember paths are workspace-relative, not host-absolute"],"tags":["cli","validation","missing-argument","search","go","siyuan"],"backgroundTag":null,"analyzedSha":"251596fc0de2f9528c00c224252fd073a99973f4","analyzedAt":"2026-08-12T21:18:37.123Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}