go-delve/delve · error

expected argument after -count/-len

Error message

expected argument after -count/-len

What it means

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.

Source

Thrown at service/api/command.go:239

				fmtMapToPriFmt := map[string]byte{
					"oct":         'o',
					"octal":       'o',
					"hex":         'x',
					"hexadecimal": 'x',
					"dec":         'd',
					"decimal":     'd',
					"bin":         'b',
					"binary":      'b',
				}
				out.Format, ok = fmtMapToPriFmt[arg]
				if !ok {
					return nil, fmt.Errorf("%q is not a valid format", arg)
				}
			}
		case "-count", "-len":
			arg := nextArg()
			if arg == "" {
				return nil, errors.New("expected argument after -count/-len")
			}
			var err error
			out.Count, err = strconv.ParseInt(arg, 0, 64)
			if err != nil || out.Count <= 0 {
				return nil, errors.New("count/len must be a positive integer")
			}
		case "-size":
			arg := nextArg()
			if arg == "" {
				return nil, errors.New("expected argument after -size")
			}
			var err error
			out.Size, err = strconv.ParseInt(arg, 0, 64)
			if err != nil || out.Size <= 0 || out.Size > 8 {
				return nil, errors.New("size must be a positive integer (<=8)")
			}
		case "-x":
			out.IsExpr = true

View on GitHub (pinned to a23773e6c3)

Solutions

  1. Provide a positive integer after the flag: x -count 10 -fmt x &mySlice
  2. Use -len equivalently: x -len 8 ... (both accept the same value)
  3. Validate that the count variable is a positive integer before composing the command

Example fix

// before
out, err := api.ParseExamineMemoryArg([]string{"-count", "-fmt", "x", "&arr"})

// after
out, err := api.ParseExamineMemoryArg([]string{"-count", "10", "-fmt", "x", "&arr"})
Defensive patterns

Strategy: validation

Validate before calling

// validate count before parsing
count := "10"
if n, err := strconv.ParseInt(count, 0, 64); err != nil || n <= 0 {
    panic("-count requires a positive integer")
}
out, err := api.ParseExamineMemoryArg([]string{"-count", count, "&arr"})

Type guard

func validCount(s string) bool {
    n, err := strconv.ParseInt(s, 0, 64)
    return err == nil && n > 0
}

Prevention

When it happens

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

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

Related errors


AI-assisted analysis of go-delve/delve@a23773e6c3 (2026-08-31). Data as JSON: /api/errors/6f6692401f886f84. Report an issue: GitHub.