{"record":{"id":"914b5cf29650e78e","repo":"go-delve/delve","slug":"wrong-number-of-arguments-watch-r-w-rw-expr","errorCode":null,"errorMessage":"wrong number of arguments: watch [-r|-w|-rw] <expr>","messagePattern":"wrong number of arguments: watch \\[-r\\|-w\\|-rw\\] <expr>","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/terminal/command.go","lineNumber":2077,"sourceCode":"\t}\n\tswitch editor {\n\tcase \"code\":\n\t\treturn runEditor(\"--goto\", fmt.Sprintf(\"%s:%d\", file, lineno))\n\tcase \"zed\":\n\t\treturn runEditor(fmt.Sprintf(\"%s:%d:0\", file, lineno))\n\tcase \"hx\":\n\t\treturn runEditor(fmt.Sprintf(\"%s:%d\", file, lineno))\n\tcase \"vi\", \"vim\", \"nvim\":\n\t\treturn runEditor(fmt.Sprintf(\"+%d\", lineno), file)\n\tdefault:\n\t\treturn runEditor(fmt.Sprintf(\"+%d\", lineno), file)\n\t}\n}\n\nfunc watchpoint(t *Term, ctx callContext, args string) error {\n\tv := strings.SplitN(args, \" \", 2)\n\tif len(v) != 2 {\n\t\treturn errors.New(\"wrong number of arguments: watch [-r|-w|-rw] <expr>\")\n\t}\n\tvar wtype api.WatchType\n\tswitch v[0] {\n\tcase \"-r\":\n\t\twtype = api.WatchRead\n\tcase \"-w\":\n\t\twtype = api.WatchWrite\n\tcase \"-rw\":\n\t\twtype = api.WatchRead | api.WatchWrite\n\tdefault:\n\t\treturn fmt.Errorf(\"wrong argument %q to watch\", v[0])\n\t}\n\tbp, err := t.client.CreateWatchpoint(ctx.Scope, v[1], wtype)\n\tif err != nil {\n\t\treturn err\n\t}\n\tfmt.Fprintf(t.stdout, \"%s set at %s\\n\", formatBreakpointName(bp, true), t.formatBreakpointLocation(bp))\n\treturn nil","sourceCodeStart":2059,"sourceCodeEnd":2095,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/terminal/command.go#L2059-L2095","documentation":"The 'watch' command requires exactly two space-separated tokens: a mode flag (-r, -w, or -rw) and the expression to watch. Splitting the args on the first space must yield 2 parts; if there is no space (or args are empty) the required information is missing and Delve rejects the invocation with this usage error.","triggerScenarios":"Running 'watch' with no arguments, 'watch myVar' (expression but no mode flag), or any form where strings.SplitN(args, \" \", 2) returns fewer than 2 elements inside watchpoint (pkg/terminal/command.go).","commonSituations":"Users forgetting the -r/-w flag, quoting multi-word expressions without a leading flag, or copying examples that omit the mode.","solutions":["Include a mode flag and expression: 'watch -w <expr>' for write watchpoints, 'watch -r <expr>' for read, 'watch -rw <expr>' for both.","Ensure a space separates the flag from the expression.","Check 'help watch' for the exact accepted syntax."],"exampleFix":"// before\n(dlv) watch myVar\n// after\n(dlv) watch -w myVar","handlingStrategy":"validation","validationCode":"func validateWatchArgs(args string) error {\n    parts := strings.SplitN(args, \" \", 2)\n    if len(parts) != 2 || parts[1] == \"\" {\n        return errors.New(\"usage: watch [-r|-w|-rw] <expr>\")\n    }\n    switch parts[0] {\n    case \"-r\", \"-w\", \"-rw\":\n        return nil\n    }\n    return fmt.Errorf(\"invalid watch mode %q\", parts[0])\n}","typeGuard":"func isWatchMode(tok string) bool {\n    return tok == \"-r\" || tok == \"-w\" || tok == \"-rw\"\n}","tryCatchPattern":"if err := cmd.Watchpoint(term, ctx, args); err != nil {\n    if strings.HasPrefix(err.Error(), \"wrong number of arguments: watch\") {\n        return fmt.Errorf(\"bad watch invocation %q: %w\", args, err)\n    }\n    return err\n}","preventionTips":["Always prefix watch expressions with -r, -w, or -rw","Keep a space between the flag and the expression","Validate scripted watch commands before sending them to the terminal"],"tags":["terminal","cli-usage","watchpoint"],"backgroundTag":"invalid-command-arguments","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}