siyuan-note/siyuan · error
--left and --right are required
Error message
--left and --right are required
What it means
The `siyuan repo diff` command compares two repo snapshots and requires both `--left` and `--right` snapshot IDs. The RunE handler returns this error when either is empty, before calling model.DiffRepoSnapshots.
Solutions
- Re-run with both flags: `siyuan repo diff --left <id1> --right <id2>`
- Obtain both snapshot IDs (e.g. from snapshot list output) before diffing
- Check that neither ID variable is empty in generated command lines
Example fix
// before siyuan repo diff --right 20240101120000-xyz // after siyuan repo diff --left 20240101120000-abc --right 20240101120000-xyz
Defensive patterns
Strategy: validation
Validate before calling
[ -n "$LEFT" ] && [ -n "$RIGHT" ] || { echo "repo diff: need --left and --right" >&2; exit 2; }
siyuan repo diff --left "$LEFT" --right "$RIGHT" Type guard
function requireBoth(a, b) { if (!a || !b) throw new Error('--left and --right are required'); } Try / catch
siyuan repo diff --left "$LEFT" --right "$RIGHT" || { echo 'diff needs two snapshot IDs'; } Prevention
- There is no default endpoint (no HEAD-like implicit snapshot); supply both IDs
- Build diff command lines programmatically and assert both variables are non-empty
- Quote both flag values in shell scripts
When it happens
Trigger: Running `siyuan repo diff` with only one of `--left`/`--right`, or neither; e.g. `siyuan repo diff --left <id>`.
Common situations: Assuming HEAD/current-workspace defaults exist (they do not; both endpoints are mandatory); scripts building the diff line where one endpoint variable is empty.
Understand the failure class
Background: "--flag is required" and "must specify" CLI errors: how missing-required-flag validation works and how to fix it — this error's family across 20 libraries.
Related errors
- --av and --ids are required
- --av, --key, --item and --value are required
- --block is required for non-detached rows
- --file is required
- --id and --name are required
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/fd52379a82f10220.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/cli/cmd/repo.go:182
if err := model.CheckoutRepoDirect(id); err != nil {
return err
}
model.AppendPushReloadFiletreeEntry()
model.AppendPushReloadUIEntry()
fmt.Println("ok")
return nil
},
}
var repoDiffCmd = &cobra.Command{
Use: "diff --left <id> --right <id>",
Short: "Diff two snapshots",
RunE: func(cmd *cobra.Command, args []string) error {
left, _ := cmd.Flags().GetString("left")
right, _ := cmd.Flags().GetString("right")
if left == "" || right == "" {
return fmt.Errorf("--left and --right are required")
}
diff, err := model.DiffRepoSnapshots(left, right)
if err != nil {
return err
}
data, _ := json.MarshalIndent(diff, "", " ")
fmt.Println(string(data))
return nil
},
}
var repoSearchCmd = &cobra.Command{
Use: "search <keyword>",
Short: "Search files in snapshots",
Args: cobra.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
keyword := args[0]
page, _ := cmd.Flags().GetInt("page")View on GitHub (pinned to 9f775e8a12)