siyuan-note/siyuan · error

--path is required

Error message

--path is required

What it means

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.

Source

Thrown at kernel/cli/cmd/file.go:283

	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 err
		}
		switch outputFormat {
		case "json":
			data, _ := json.MarshalIndent(results, "", "  ")

View on GitHub (pinned to 251596fc0d)

Solutions

  1. Add the search root: `siyuan file grep --pattern "TODO" --path data/`
  2. Use `.` or `data/` to scope to the workspace data directory

Example fix

// before
siyuan file grep --pattern "TODO"
// after
siyuan file grep --pattern "TODO" --path data/
Defensive patterns

Strategy: validation

Validate before calling

if path == "" {
    return errors.New("a workspace-relative search path is required")
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of siyuan-note/siyuan@251596fc0d (2026-08-12). Data as JSON: /api/errors/b7be57416b6110a1. Report an issue: GitHub.