{"record":{"id":"d631c934618a28c8","repo":"go-delve/delve","slug":"cannot-unmarshal-v-into-q-of-type-v","errorCode":null,"errorMessage":"cannot unmarshal %v into %q of type %v","messagePattern":"cannot unmarshal (.+?) into %q of type (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"service/dap/types.go","lineNumber":305,"sourceCode":"\tLaunchAttachCommonConfig\n}\n\n// unmarshalLaunchAttachArgs wraps unmarshaling of launch/attach request's\n// arguments attribute. Upon unmarshal failure, it returns an error massaged\n// to be suitable for end-users.\nfunc unmarshalLaunchAttachArgs(input json.RawMessage, config any) error {\n\tif err := json.Unmarshal(input, config); err != nil {\n\t\tif uerr, ok := err.(*json.UnmarshalTypeError); ok {\n\t\t\t// Format json.UnmarshalTypeError error string in our own way. E.g.,\n\t\t\t//   \"json: cannot unmarshal number into Go struct field LaunchArgs.substitutePath of type dap.SubstitutePath\"\n\t\t\t//   => \"cannot unmarshal number into 'substitutePath' of type {from:string, to:string}\"\n\t\t\t//   \"json: cannot unmarshal number into Go struct field LaunchArgs.program of type string\" (go1.16)\n\t\t\t//   => \"cannot unmarshal number into 'program' of type string\"\n\t\t\ttyp := uerr.Type.String()\n\t\t\tif uerr.Field == \"substitutePath\" {\n\t\t\t\ttyp = `{\"from\":string, \"to\":string}`\n\t\t\t}\n\t\t\treturn fmt.Errorf(\"cannot unmarshal %v into %q of type %v\", uerr.Value, uerr.Field, typ)\n\t\t}\n\t\treturn err\n\t}\n\treturn nil\n}\n\nfunc prettyPrint(config any) string {\n\tpretty, err := json.MarshalIndent(config, \"\", \"\\t\")\n\tif err != nil {\n\t\treturn fmt.Sprintf(\"%#v\", config)\n\t}\n\treturn string(pretty)\n}\n\n// BuildFlags is either string or []string.\ntype BuildFlags struct {\n\tvalue any\n}","sourceCodeStart":287,"sourceCodeEnd":323,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/service/dap/types.go#L287-L323","documentation":"A launch/attach argument field was given a JSON value of the wrong Go type. Delve intercepts encoding/json's UnmarshalTypeError and rewrites it into a friendlier message naming the JSON value, the field, and the expected type (with substitutePath specially rewritten to {\"from\":string,\"to\":string}).","triggerScenarios":"onLaunchRequest or onAttachRequest where any field of LaunchArgs has a mismatched type, e.g. \"program\": 42, \"port\": \"2345\" vs number, or \"mode\": 1.","commonSituations":"Hand-edited launch.json with wrong-typed values, numeric program names, buildFlags given a wrong type handled separately, copy-paste between client configs.","solutions":["Read the field name and expected type in the message and fix the JSON type in launch.json","Wrap the value in quotes if a string is expected (program, mode, cwd, etc.)","Use a number if a numeric field (e.g. port) is named","Run your launch.json through schema validation before starting a debug session"],"exampleFix":"// before\n{\"request\":\"launch\",\"mode\":\"debug\",\"program\":12345}\n// after\n{\"request\":\"launch\",\"mode\":\"debug\",\"program\":\"/path/to/cmd\"}","handlingStrategy":"validation","validationCode":"func checkLaunchArgTypes(cfg map[string]any) error {\n  strFields := []string{\"program\",\"mode\",\"cwd\",\"backend\"}\n  for _, f := range strFields { if v, ok := cfg[f]; ok && v != nil { if _, ok := v.(string); !ok { return fmt.Errorf(\"field %q must be a string\", f) } } }\n  return nil\n}","typeGuard":"func expectString(v any) (string, bool) { s, ok := v.(string); return s, ok }","tryCatchPattern":"if err := startSession(args); err != nil { if strings.Contains(err.Error(), \"cannot unmarshal\") { /* parse field/type from message and fix launch.json */ } return err }","preventionTips":["Validate launch.json against the DAP delve schema","Quote all string-typed fields; check numeric fields are numbers","Copy configs between editors carefully — type conventions differ"],"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"}