{"record":{"id":"ef6d2a917e44b51e","repo":"siyuan-note/siyuan","slug":"pattern-is-required","errorCode":null,"errorMessage":"--pattern is required","messagePattern":"--pattern is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/cli/cmd/file.go","lineNumber":279,"sourceCode":"\t\treturn err\n\t}\n\tdefer srcF.Close()\n\tdstF, err := os.Create(dst)\n\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","sourceCodeStart":261,"sourceCodeEnd":297,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/251596fc0de2f9528c00c224252fd073a99973f4/kernel/cli/cmd/file.go#L261-L297","documentation":"Thrown by the `file grep` subcommand when the `--pattern` flag is empty. The pattern is the regular expression passed to `gulu.File.Grep`; an empty pattern would match everything and is treated as a usage error. The check runs before the search path is resolved.","triggerScenarios":"Running `siyuan file grep --path data/` with no `--pattern`, or with `--pattern \"\"`. The RunE reads the flag and returns the error before touching the filesystem.","commonSituations":"Forgetting the regex argument when adapting a grep habit from shell; passing a variable that evaluated to empty; misreading the flag order.","solutions":["Supply a regex: `siyuan file grep --pattern \"TODO\" --path data/`","Check `siyuan file grep --help` for the full flag set including `--include` and `--context`"],"exampleFix":"// before\nsiyuan file grep --path data/\n// after\nsiyuan file grep --pattern \"TODO|FIXME\" --path data/ --include *.md","handlingStrategy":"validation","validationCode":"if pattern == \"\" {\n    return errors.New(\"a non-empty regex pattern is required\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat `--pattern` and `--path` as a required pair for `file grep`","Quote regexes to avoid shell interpretation","Test the regex with a small scope first"],"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"}