go-delve/delve · error

can not convert value of type %s to %s: %v

Error message

can not convert value of type %s to %s: %v

What it means

`convertToEface` failed while converting a variable into an `interface {}`: either the DWARF type could not be mapped to a Go runtime type (`dwarfToRuntimeType` returned an error) or the runtime type was not found/direct. The low-level cause is wrapped into this message.

Source

Thrown at pkg/proc/variables.go:1516

// interface or a pointer shaped variable (map, channel, pointer or struct
// containing a single pointer)
func convertToEface(srcv, dstv *Variable) error {
	if dstv.RealType.String() != "interface {}" {
		return &typeConvErr{srcv.DwarfType, dstv.RealType}
	}
	if _, isiface := srcv.RealType.(*godwarf.InterfaceType); isiface {
		// iface -> eface conversion
		_type, data, _ := srcv.readInterface()
		if srcv.Unreadable != nil {
			return srcv.Unreadable
		}
		_type = _type.maybeDereference()
		dstv.writeEmptyInterface(_type.Addr, data)
		return nil
	}
	typeAddr, direct, runtimeTypeFound, err := dwarfToRuntimeType(srcv.bi, srcv.mem, srcv.RealType)
	if err != nil {
		return fmt.Errorf("can not convert value of type %s to %s: %v", srcv.DwarfType.String(), dstv.DwarfType.String(), err)
	}
	if !runtimeTypeFound || !direct {
		return &typeConvErr{srcv.DwarfType, dstv.RealType}
	}
	return dstv.writeEmptyInterface(typeAddr, srcv)
}

func readStringInfo(mem MemoryReadWriter, arch *Arch, addr uint64, typ *godwarf.StringType) (uint64, int64, error) {
	// string data structure is always two ptrs in size. Addr, followed by len
	// https://research.swtch.com/godata

	mem = cacheMemory(mem, addr, arch.PtrSize()*2)

	var strlen int64
	var outaddr uint64
	var err error

	for _, field := range typ.StructType.Field {

View on GitHub (pinned to a23773e6c3)

Solutions

  1. Check the wrapped cause (%v) for the underlying runtime-type lookup failure.
  2. Convert to a concrete Go type first, or set the field directly rather than through an interface.
  3. Ensure the binary was built without stripping DWARF/types sections (`-w`, `-s` flags removed).
  4. For cgo values, avoid interface conversion in the debugger; inspect fields individually.

Example fix

// before (delve cli)
set iface = cStructValue // can not convert value of type C.struct_foo to interface {}
// after
set ifaceField.intField = cStructValue.intField
Defensive patterns

Strategy: validation

Validate before calling

// Only assign values whose types are normal Go types to interfaces:
// (dlv) set iface = concreteGoValue   // OK
// (dlv) set iface = cgoValue          // may fail; use field-wise assignment instead

Try / catch

err := dstv.convertToEface(_type, srcv)
if err != nil {
    var tc *typeConvErr
    if errors.As(err, &tc) || strings.Contains(err.Error(), "can not convert value of type") {
        // fall back to assigning concrete fields
    }
}

Prevention

When it happens

Trigger: Assigning or converting a value into an eface variable during evaluation (Delve's internal conversion used by `set` and certain expression evaluations) when `srcv.RealType` has no direct runtime-type equivalent, or when reading the runtime type structures from memory fails.

Common situations: Using `set` on interface variables with values whose DWARF types cannot be resolved to runtime types (e.g. C types via cgo, types from cgo-generated code); debugging stripped or oddly compiled binaries where the types link section is incomplete.

Related errors


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