siyuan-note/siyuan · error
--pattern is required
Error message
--pattern is required
What it means
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.
Source
Thrown at kernel/cli/cmd/file.go:279
return err
}
defer srcF.Close()
dstF, err := os.Create(dst)
if err != nil {
return err
}
defer dstF.Close()
_, err = io.Copy(dstF, srcF)
return err
}
var fileGrepCmd = &cobra.Command{
Use: "grep --pattern <regex> --path <path>",
Short: "Search file contents with regex",
RunE: func(cmd *cobra.Command, args []string) error {
pattern, _ := cmd.Flags().GetString("pattern")
if pattern == "" {
return fmt.Errorf("--pattern is required")
}
relPath, _ := cmd.Flags().GetString("path")
if relPath == "" {
return fmt.Errorf("--path is required")
}
abs, err := absPath(relPath)
if err != nil {
return err
}
include, _ := cmd.Flags().GetString("include")
ctx, _ := cmd.Flags().GetInt("context")
max, _ := cmd.Flags().GetInt("limit")
if max <= 0 {
max = 200
}
results, err := gulu.File.Grep(abs, include, pattern, ctx, max)
if err != nil {
return errView on GitHub (pinned to 251596fc0d)
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`
Example fix
// before siyuan file grep --path data/ // after siyuan file grep --pattern "TODO|FIXME" --path data/ --include *.md
Defensive patterns
Strategy: validation
Validate before calling
if pattern == "" {
return errors.New("a non-empty regex pattern is required")
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: Forgetting the regex argument when adapting a grep habit from shell; passing a variable that evaluated to empty; misreading the flag order.
Related errors
AI-assisted analysis of siyuan-note/siyuan@251596fc0d (2026-08-12).
Data as JSON: /api/errors/ef6d2a917e44b51e.
Report an issue: GitHub.