go-delve/delve · error
second slice argument must be empty for maps
Error message
second slice argument must be empty for maps
What it means
When reslicing a map expression (evalReslice), delve treats [low:] on a map as 'skip low entries' (a display feature; [0:0] returns the whole map). Providing a high bound on a map is unsupported, so this error is thrown. It is a deliberate restriction of the debugger's map-slicing syntax, not a Go language error.
Source
Thrown at pkg/proc/eval.go:2280
if xev.Unreadable != nil {
stack.err = xev.Unreadable
return
}
if !op.HasHigh {
high = xev.Len
}
switch xev.Kind {
case reflect.Slice, reflect.Array, reflect.String:
if xev.Base == 0 {
stack.err = fmt.Errorf("can not slice %q", astutil.ExprToString(op.Node.X))
return
}
stack.pushErr(xev.reslice(low, high, op.TrustLen))
return
case reflect.Map:
if op.Node.High != nil {
stack.err = errors.New("second slice argument must be empty for maps")
return
}
xev.mapSkip += int(low)
xev.mapIterator(0) // reads map length
if int64(xev.mapSkip) >= xev.Len {
stack.err = errors.New("map index out of bounds")
return
}
stack.push(xev)
return
case reflect.Ptr:
if xev.Flags&VariableCPtr != 0 {
stack.pushErr(xev.reslice(low, high, op.TrustLen))
return
}
fallthrough
default:
stack.err = fmt.Errorf("can not slice %q (type %s)", astutil.ExprToString(op.Node.X), xev.TypeString())View on GitHub (pinned to a23773e6c3)
Solutions
- Use only a low bound for maps: m[5:] to skip the first 5 entries.
- Use m[0:0] to request the entire map (delve's documented hack).
- If you need a bounded number of entries, rely on the configured max variable string length / max map count instead of a high slice index.
- In tooling, check the variable's Kind == reflect.Map and strip the High expression before sending a reslice request.
Example fix
// before print bigMap[0:20] // after print bigMap[0:] // or bigMap[0:0] for the whole map
Defensive patterns
Strategy: validation
Validate before calling
v, _ := scope.EvalExpression(mapExpr, cfg)
if v.Kind == reflect.Map && strings.Contains(expr, ":") {
if high, ok := resliceHigh(expr); ok {
return fmt.Errorf("drop the high bound for maps: %s[%v:]", mapExpr, resliceLow(expr))
}
} Type guard
func validMapReslice(kind reflect.Kind, hasHigh bool) bool {
return kind != reflect.Map || !hasHigh
} Try / catch
_, err := scope.EvalExpression(expr, cfg)
if err != nil && strings.Contains(err.Error(), "second slice argument must be empty for maps") {
expr = stripHighBound(expr) // m[a:b] -> m[a:]
_, err = scope.EvalExpression(expr, cfg)
} Prevention
- Only use [low:] (no high bound) when slicing map expressions
- Use m[0:0] to fetch an entire map in delve
- Validate user-supplied slice expressions against the variable's Kind before eval
- Never assume Go slice semantics apply to map reslices in the debugger
When it happens
Trigger: Evaluating a map expression with a two-index slice like m[1:5] or m[0:10] in print/eval; DAP/RPC clients building reslice operations with High set on a map-typed variable.
Common situations: Users typing m[0:10] expecting Go-style slicing (maps are not sliceable in Go either); UIs that generically offer low/high slice inputs for any collection including maps.
Related errors
- map index out of bounds
- variable to reslice is not an array, slice, or map
- map index out of bounds
- can not access unreadable map: %v
- could not decode first frame
AI-assisted analysis of go-delve/delve@a23773e6c3 (2026-08-31).
Data as JSON: /api/errors/b47f75a2654701b6.
Report an issue: GitHub.