go-delve/delve · error

error setting argument %q: can not convert %s to %s: %s

Error message

error setting argument %q: can not convert %s to %s: %s

What it means

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.

Source

Thrown at pkg/terminal/starbind/conv.go:634

// This works similarly to encoding/json.Unmarshal and similar functions,
// but instead of getting its input from a byte buffer, it uses a
// starlark.Value.
func unmarshalStarlarkValue(val starlark.Value, dst any, path string) error {
	return unmarshalStarlarkValueIntl(val, reflect.ValueOf(dst), path)
}

func unmarshalStarlarkValueIntl(val starlark.Value, dst reflect.Value, path string) (err error) {
	defer func() {
		// catches reflect panics
		ierr := recover()
		if ierr != nil {
			err = fmt.Errorf("error setting argument %q to %s: %v", path, val, ierr)
		}
	}()

	converr := func(args ...string) error {
		if len(args) > 0 {
			return fmt.Errorf("error setting argument %q: can not convert %s to %s: %s", path, val, dst.Type().String(), args[0])
		}
		return fmt.Errorf("error setting argument %q: can not convert %s to %s", path, val, dst.Type().String())
	}

	if _, isnone := val.(starlark.NoneType); isnone {
		return nil
	}

	for dst.Kind() == reflect.Ptr {
		if dst.IsNil() {
			dst.Set(reflect.New(dst.Type().Elem()))
		}
		dst = dst.Elem()
	}

	switch val := val.(type) {
	case starlark.Bool:
		dst.SetBool(bool(val))

View on GitHub (pinned to a23773e6c3)

Solutions

  1. Convert explicitly in the script: int(val), float(val), str(val) before the call
  2. Fix the literal in the script to the correct type
  3. Check the API signature's expected Go type and reshape the argument
  4. If a numeric string must be parsed, pre-validate it with int() and handle failure

Example fix

# before
api.SetBreakpoint(t, "file.go", "10", bp)   # string into int line
# after
api.SetBreakpoint(t, "file.go", int("10"), bp)
Defensive patterns

Strategy: validation

Validate before calling

if dst_kind == 'int':
    assert isinstance(val, int), "need int, got %s" % type(val)
elif dst_kind == 'string':
    assert isinstance(val, str), "need string, got %s" % type(val)

Type guard

def convertible(val, dst_type_name):
    return (dst_type_name.startswith('int') and isinstance(val, int)) or \
           (dst_type_name.startswith('float') and isinstance(val, (int, float))) or \
           (dst_type_name.startswith('string') and isinstance(val, str)) or \
           (dst_type_name.startswith('bool') and isinstance(val, bool))

Try / catch

try:
    api.SomeCall(val)
except Exception as e:
    if "can not convert" in str(e):
        api.SomeCall(explicit_convert(val))
    else:
        raise

Prevention

When it happens

Trigger: 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.

Common situations: Scripts reading user input as strings and feeding them to numeric API parameters, or assuming Starlark ints auto-convert into Go float fields.

Related errors


AI-assisted analysis of go-delve/delve@a23773e6c3 (2026-08-31). Data as JSON: /api/errors/681f0bb2474bc321. Report an issue: GitHub.