go-delve/delve · error
cannot unmarshal %v into "buildFlags" of type []string or st
Error message
cannot unmarshal %v into "buildFlags" of type []string or string
What it means
The buildFlags launch argument accepts either a single string or an array of strings (custom flexType). If the JSON value is neither (e.g. a number, boolean, or object), the custom UnmarshalJSON returns this error, dropping the previous value.
Source
Thrown at service/dap/types.go:339
type BuildFlags struct {
value any
}
func (s *BuildFlags) UnmarshalJSON(b []byte) error {
if v := string(b); v == "" || v == "null" {
s.value = nil
return nil
}
var strs []string
if err := json.Unmarshal(b, &strs); err == nil {
s.value = strs
return nil
}
var str string
if err := json.Unmarshal(b, &str); err != nil {
s.value = nil
if uerr, ok := err.(*json.UnmarshalTypeError); ok {
return fmt.Errorf(`cannot unmarshal %v into "buildFlags" of type []string or string`, uerr.Value)
}
return err
}
s.value = str
return nil
}
View on GitHub (pinned to a23773e6c3)
Solutions
- Set buildFlags to a single string: "buildFlags": "-tags=integration"
- Or an array of strings: "buildFlags": ["-tags=integration","-v"]
- Do not pass numbers, booleans or objects
- Split multiple flags into array elements rather than one object
Example fix
// before "buildFlags": true // after "buildFlags": ["-tags=integration"]
Defensive patterns
Strategy: type-guard
Validate before calling
func validBuildFlags(v any) bool { switch v.(type) { case string, []string, []any, nil: return true; default: return false } } Type guard
func asBuildFlags(v any) ([]string, bool) {
switch t := v.(type) {
case string: return []string{t}, true
case []string: return t, true
case []any: out := []string{}; for _, e := range t { s, ok := e.(string); if !ok { return nil, false }; out = append(out, s) }; return out, true
default: return nil, false
}
} Try / catch
if err := launch(cfg); err != nil { if strings.Contains(err.Error(), "buildFlags") { /* coerce to string or []string and retry */ } return err } Prevention
- Send buildFlags only as a string or array of strings
- Never use booleans/objects for buildFlags
- Split multiple flags into separate array elements
When it happens
Trigger: onLaunchRequest/onAttachRequest with e.g. "buildFlags": 42 or "buildFlags": {"a":1} — an UnmarshalTypeError from both the []string and string decode attempts.
Common situations: Users setting buildFlags to a boolean (true) intending 'enable', or nesting flags as an object of key/value pairs.
Related errors
- cannot unmarshal %v into %q of type %v
- cannot use %s as 'substitutePath' of type {"from":string, "t
- variable to reslice is not an array, slice, or map
- count/len must be a positive integer
- expected argument after -size
AI-assisted analysis of go-delve/delve@a23773e6c3 (2026-08-31).
Data as JSON: /api/errors/2eec399e0038fc25.
Report an issue: GitHub.