{"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/9f775e8a12daef8255556097396f9b2739078892/kernel/cli/cmd/file.go#L261-L297","documentation":"The SiYuan kernel CLI `file grep` command requires a regex pattern via --pattern. The command reads the flag with cmd.Flags().GetString and returns this error immediately when the value is empty. It is a user-input guard, not an internal failure.","triggerScenarios":"Running `siyuan file grep` (or `file grep --path <path>`) without --pattern, or passing --pattern \"\" (empty string).","commonSituations":"Developer forgets the flag when scripting searches; a shell variable holding the pattern is empty due to an earlier failed capture; flags copied from a doc example omit the pattern.","solutions":["Re-run the command with --pattern <regex>, e.g. file grep --pattern \"TODO\" --path \"data/notebooks\"","Check that the shell variable supplying the pattern is non-empty before invoking the CLI","Run `siyuan file grep --help` to see the expected flags"],"exampleFix":"// before\nfile grep --path data/notebook\n// after\nfile grep --pattern \"TODO\" --path data/notebook","handlingStrategy":"validation","validationCode":"if [ -z \"$PATTERN\" ]; then echo \"--pattern is required\" >&2; exit 1; fi\nsiyuan file grep --pattern \"$PATTERN\" --path \"$PATH_ARG\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass --pattern explicitly; never rely on ambient variables without a non-empty check","Keep a shell function wrapper that validates required flags before invoking the CLI","Consult `file grep --help` for the canonical flag list"],"tags":["cli","missing-flag","validation"],"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"}