{"record":{"id":"681f0bb2474bc321","repo":"go-delve/delve","slug":"error-setting-argument-q-can-not-convert-s-to","errorCode":null,"errorMessage":"error setting argument %q: can not convert %s to %s: %s","messagePattern":"error setting argument %q: can not convert (.+?) to (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/terminal/starbind/conv.go","lineNumber":634,"sourceCode":"// This works similarly to encoding/json.Unmarshal and similar functions,\n// but instead of getting its input from a byte buffer, it uses a\n// starlark.Value.\nfunc unmarshalStarlarkValue(val starlark.Value, dst any, path string) error {\n\treturn unmarshalStarlarkValueIntl(val, reflect.ValueOf(dst), path)\n}\n\nfunc unmarshalStarlarkValueIntl(val starlark.Value, dst reflect.Value, path string) (err error) {\n\tdefer func() {\n\t\t// catches reflect panics\n\t\tierr := recover()\n\t\tif ierr != nil {\n\t\t\terr = fmt.Errorf(\"error setting argument %q to %s: %v\", path, val, ierr)\n\t\t}\n\t}()\n\n\tconverr := func(args ...string) error {\n\t\tif len(args) > 0 {\n\t\t\treturn fmt.Errorf(\"error setting argument %q: can not convert %s to %s: %s\", path, val, dst.Type().String(), args[0])\n\t\t}\n\t\treturn fmt.Errorf(\"error setting argument %q: can not convert %s to %s\", path, val, dst.Type().String())\n\t}\n\n\tif _, isnone := val.(starlark.NoneType); isnone {\n\t\treturn nil\n\t}\n\n\tfor dst.Kind() == reflect.Ptr {\n\t\tif dst.IsNil() {\n\t\t\tdst.Set(reflect.New(dst.Type().Elem()))\n\t\t}\n\t\tdst = dst.Elem()\n\t}\n\n\tswitch val := val.(type) {\n\tcase starlark.Bool:\n\t\tdst.SetBool(bool(val))","sourceCodeStart":616,"sourceCodeEnd":652,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/terminal/starbind/conv.go#L616-L652","documentation":"The converr helper in unmarshalStarlarkValueIntl: the Starlark value's type cannot be converted to the destination Go type dst.Type(). The variant with a trailing detail appends a reason (e.g. specific parse failure) as the final %s.","triggerScenarios":"Passing a Starlark value of one scalar type where the Go parameter needs another inconvertible one — e.g. a string \"abc\" into an int field (detail: strconv error), or a dict into a string field, when invoking a Delve API from Starlark.","commonSituations":"Scripts reading user input as strings and feeding them to numeric API parameters, or assuming Starlark ints auto-convert into Go float fields.","solutions":["Convert explicitly in the script: int(val), float(val), str(val) before the call","Fix the literal in the script to the correct type","Check the API signature's expected Go type and reshape the argument","If a numeric string must be parsed, pre-validate it with int() and handle failure"],"exampleFix":"# before\napi.SetBreakpoint(t, \"file.go\", \"10\", bp)   # string into int line\n# after\napi.SetBreakpoint(t, \"file.go\", int(\"10\"), bp)","handlingStrategy":"validation","validationCode":"if dst_kind == 'int':\n    assert isinstance(val, int), \"need int, got %s\" % type(val)\nelif dst_kind == 'string':\n    assert isinstance(val, str), \"need string, got %s\" % type(val)","typeGuard":"def convertible(val, dst_type_name):\n    return (dst_type_name.startswith('int') and isinstance(val, int)) or \\\n           (dst_type_name.startswith('float') and isinstance(val, (int, float))) or \\\n           (dst_type_name.startswith('string') and isinstance(val, str)) or \\\n           (dst_type_name.startswith('bool') and isinstance(val, bool))","tryCatchPattern":"try:\n    api.SomeCall(val)\nexcept Exception as e:\n    if \"can not convert\" in str(e):\n        api.SomeCall(explicit_convert(val))\n    else:\n        raise","preventionTips":["Convert values with int()/float()/str() before API calls","Validate numeric strings parse before passing them","Match argument order to the API signature"],"tags":["starlark","delve","scripting","type-conversion"],"backgroundTag":"starlark-argument-conversion-failed","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}