go-delve/delve · error

count/len must be a positive integer

Error message

count/len must be a positive integer

What it means

ParseExamineMemoryArg parses the arguments of the DAP `examineMemory`/`x` command. The `-count`/`-len` flag specifies how many memory chunks to read, and it must parse as an integer (base 0, so hex/0x allowed) strictly greater than zero. Delve throws this error when the argument is missing, non-numeric, or <= 0.

Source

Thrown at service/api/command.go:244

					"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
			// remaining args are going to be interpreted as expression
			out.Operand = strings.Join(args, " ")
			break loop
		default:
			if len(args) > 0 {

View on GitHub (pinned to a23773e6c3)

Solutions

  1. Pass a positive integer for -count/-len, e.g. `x -count 20 -size 8 0xc000010000`
  2. Remember base-0 parsing accepts 0x-prefixed hex; verify the value has no stray characters or suffixes
  3. Omit -count entirely if a default count is acceptable instead of passing 0

Example fix

// before
"x -count 0 -size 8 0xc000010000"
// after
"x -count 16 -size 8 0xc000010000"
Defensive patterns

Strategy: validation

Validate before calling

func validCount(v string) bool {
	n, err := strconv.ParseInt(v, 0, 64)
	return err == nil && n > 0
}
if !validCount(countArg) { /* fix or prompt before calling examineMemory */ }

Prevention

When it happens

Trigger: Calling the `examineMemory` (aliases `x`) DAP command with `-count <bad>` or `-len <bad>` where the value is empty (caught earlier), not a number (e.g. `-count abc`, `-count 1_000`), or zero/negative (`-count 0`, `-count -5`).

Common situations: IDE clients computing the count from a UI field that allows 0; users habituated to other tools' `x` command which defaults or allows 0; copy-pasting counts with unit suffixes like `64b`; negative counts from reversed sign in generated clients.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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