{"record":{"id":"2eec399e0038fc25","repo":"go-delve/delve","slug":"cannot-unmarshal-v-into-buildflags-of-type-st","errorCode":null,"errorMessage":"cannot unmarshal %v into \"buildFlags\" of type []string or string","messagePattern":"cannot unmarshal (.+?) into \"buildFlags\" of type \\[\\]string or string","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"service/dap/types.go","lineNumber":339,"sourceCode":"type BuildFlags struct {\n\tvalue any\n}\n\nfunc (s *BuildFlags) UnmarshalJSON(b []byte) error {\n\tif v := string(b); v == \"\" || v == \"null\" {\n\t\ts.value = nil\n\t\treturn nil\n\t}\n\tvar strs []string\n\tif err := json.Unmarshal(b, &strs); err == nil {\n\t\ts.value = strs\n\t\treturn nil\n\t}\n\tvar str string\n\tif err := json.Unmarshal(b, &str); err != nil {\n\t\ts.value = nil\n\t\tif uerr, ok := err.(*json.UnmarshalTypeError); ok {\n\t\t\treturn fmt.Errorf(`cannot unmarshal %v into \"buildFlags\" of type []string or string`, uerr.Value)\n\t\t}\n\t\treturn err\n\t}\n\ts.value = str\n\treturn nil\n}\n","sourceCodeStart":321,"sourceCodeEnd":346,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/service/dap/types.go#L321-L346","documentation":"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.","triggerScenarios":"onLaunchRequest/onAttachRequest with e.g. \"buildFlags\": 42 or \"buildFlags\": {\"a\":1} — an UnmarshalTypeError from both the []string and string decode attempts.","commonSituations":"Users setting buildFlags to a boolean (true) intending 'enable', or nesting flags as an object of key/value pairs.","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"],"exampleFix":"// before\n\"buildFlags\": true\n// after\n\"buildFlags\": [\"-tags=integration\"]","handlingStrategy":"type-guard","validationCode":"func validBuildFlags(v any) bool { switch v.(type) { case string, []string, []any, nil: return true; default: return false } }","typeGuard":"func asBuildFlags(v any) ([]string, bool) {\n  switch t := v.(type) {\n  case string: return []string{t}, true\n  case []string: return t, true\n  case []any: out := []string{}; for _, e := range t { s, ok := e.(string); if !ok { return nil, false }; out = append(out, s) }; return out, true\n  default: return nil, false\n  }\n}","tryCatchPattern":"if err := launch(cfg); err != nil { if strings.Contains(err.Error(), \"buildFlags\") { /* coerce to string or []string and retry */ } return err }","preventionTips":["Send buildFlags only as a string or array of strings","Never use booleans/objects for buildFlags","Split multiple flags into separate array elements"],"tags":["dap","json","launch-config","type-mismatch"],"backgroundTag":"json-type-mismatch","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}