{"record":{"id":"6f6692401f886f84","repo":"go-delve/delve","slug":"expected-argument-after-count-len","errorCode":null,"errorMessage":"expected argument after -count/-len","messagePattern":"expected argument after -count/-len","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"service/api/command.go","lineNumber":239,"sourceCode":"\t\t\t\tfmtMapToPriFmt := map[string]byte{\n\t\t\t\t\t\"oct\":         'o',\n\t\t\t\t\t\"octal\":       'o',\n\t\t\t\t\t\"hex\":         'x',\n\t\t\t\t\t\"hexadecimal\": 'x',\n\t\t\t\t\t\"dec\":         'd',\n\t\t\t\t\t\"decimal\":     'd',\n\t\t\t\t\t\"bin\":         'b',\n\t\t\t\t\t\"binary\":      'b',\n\t\t\t\t}\n\t\t\t\tout.Format, ok = fmtMapToPriFmt[arg]\n\t\t\t\tif !ok {\n\t\t\t\t\treturn nil, fmt.Errorf(\"%q is not a valid format\", arg)\n\t\t\t\t}\n\t\t\t}\n\t\tcase \"-count\", \"-len\":\n\t\t\targ := nextArg()\n\t\t\tif arg == \"\" {\n\t\t\t\treturn nil, errors.New(\"expected argument after -count/-len\")\n\t\t\t}\n\t\t\tvar err error\n\t\t\tout.Count, err = strconv.ParseInt(arg, 0, 64)\n\t\t\tif err != nil || out.Count <= 0 {\n\t\t\t\treturn nil, errors.New(\"count/len must be a positive integer\")\n\t\t\t}\n\t\tcase \"-size\":\n\t\t\targ := nextArg()\n\t\t\tif arg == \"\" {\n\t\t\t\treturn nil, errors.New(\"expected argument after -size\")\n\t\t\t}\n\t\t\tvar err error\n\t\t\tout.Size, err = strconv.ParseInt(arg, 0, 64)\n\t\t\tif err != nil || out.Size <= 0 || out.Size > 8 {\n\t\t\t\treturn nil, errors.New(\"size must be a positive integer (<=8)\")\n\t\t\t}\n\t\tcase \"-x\":\n\t\t\tout.IsExpr = true","sourceCodeStart":221,"sourceCodeEnd":257,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/service/api/command.go#L221-L257","documentation":"ParseExamineMemoryArg accepts -count (or -len) followed by a positive integer controlling how many elements/bytes are examined. If nextArg() returns empty (flag at the end), parsing fails with 'expected argument after -count/-len'. If the value parses but is <= 0 or non-numeric, a separate 'count/len must be a positive integer' error is returned instead.","triggerScenarios":"Calling `x -count` or `x -len` as the last argument with no value, or building args programmatically where the count token is missing/empty so nextArg() returns \"\".","commonSituations":"Copy-pasting examples and dropping the numeric argument; shell scripts with an unset COUNT variable; IDE plugins constructing the command conditionally and leaving the flag dangling; typos producing an empty token.","solutions":["Provide a positive integer after the flag: x -count 10 -fmt x &mySlice","Use -len equivalently: x -len 8 ... (both accept the same value)","Validate that the count variable is a positive integer before composing the command"],"exampleFix":"// before\nout, err := api.ParseExamineMemoryArg([]string{\"-count\", \"-fmt\", \"x\", \"&arr\"})\n\n// after\nout, err := api.ParseExamineMemoryArg([]string{\"-count\", \"10\", \"-fmt\", \"x\", \"&arr\"})","handlingStrategy":"validation","validationCode":"// validate count before parsing\ncount := \"10\"\nif n, err := strconv.ParseInt(count, 0, 64); err != nil || n <= 0 {\n    panic(\"-count requires a positive integer\")\n}\nout, err := api.ParseExamineMemoryArg([]string{\"-count\", count, \"&arr\"})","typeGuard":"func validCount(s string) bool {\n    n, err := strconv.ParseInt(s, 0, 64)\n    return err == nil && n > 0\n}","tryCatchPattern":null,"preventionTips":["Always place the integer immediately after -count or -len","Use ${COUNT:?msg} in shell to catch unset count variables","Remember count must be strictly positive; 0 and negatives are rejected by the follow-up check","Prefer -len for readability when examining a fixed byte/element length"],"tags":["cli","parsing","examine-memory"],"backgroundTag":"missing-flag-argument","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}