{"record":{"id":"827b8364e631a5c5","repo":"go-delve/delve","slug":"interface-conversion-s-is-nil-not-s","errorCode":null,"errorMessage":"interface conversion: %s is nil, not %s","messagePattern":"interface conversion: (.+?) is nil, not (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/proc/eval.go","lineNumber":2144,"sourceCode":"\n// Evaluates expressions <subexpr>.(<type>)\nfunc (scope *EvalScope) evalTypeAssert(op *evalop.TypeAssert, stack *evalStack) {\n\txv := stack.pop()\n\tif xv.Kind != reflect.Interface {\n\t\tstack.err = fmt.Errorf(\"expression %q not an interface\", astutil.ExprToString(op.Node.X))\n\t\treturn\n\t}\n\txv.loadInterface(0, false, LoadFullValue())\n\tif xv.Unreadable != nil {\n\t\tstack.err = xv.Unreadable\n\t\treturn\n\t}\n\tif xv.Children[0].Unreadable != nil {\n\t\tstack.err = xv.Children[0].Unreadable\n\t\treturn\n\t}\n\tif xv.Children[0].Addr == 0 {\n\t\tstack.err = fmt.Errorf(\"interface conversion: %s is nil, not %s\", xv.DwarfType.String(), astutil.ExprToString(op.Node.Type))\n\t\treturn\n\t}\n\ttyp := op.DwarfType\n\tif typ != nil && xv.Children[0].DwarfType.Common().Name != typ.Common().Name {\n\t\tstack.err = fmt.Errorf(\"interface conversion: %s is %s, not %s\", xv.DwarfType.Common().Name, xv.Children[0].TypeString(), typ.Common().Name)\n\t\treturn\n\t}\n\t// loadInterface will set OnlyAddr for the data member since here we are\n\t// passing false to loadData, however returning the variable with OnlyAddr\n\t// set here would be wrong since, once the expression evaluation\n\t// terminates, the value of this variable will be loaded.\n\txv.Children[0].OnlyAddr = false\n\tstack.push(&xv.Children[0])\n}\n\n// Evaluates expressions <subexpr>[<subexpr>] (subscript access to arrays, slices and maps)\nfunc (scope *EvalScope) evalIndex(op *evalop.Index, stack *evalStack) {\n\tidxev := stack.pop()","sourceCodeStart":2126,"sourceCodeEnd":2162,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/proc/eval.go#L2126-L2162","documentation":"After loading an interface value for a type assertion '<iface>.(T)', Delve checks the dynamic value stored in the interface. If the interface is nil (the data child has Addr == 0, meaning no dynamic value), the assertion fails with 'interface conversion: <iface type> is nil, not <T>'.","triggerScenarios":"Evaluating 'x.(T)' (print, call, breakpoint condition, watchpoint) where x is a nil interface — its type is known but it holds no dynamic value.","commonSituations":"Asserting on interface variables that were never assigned, function parameters of interface type that the caller passed as nil, or error variables that are nil at the point of inspection.","solutions":["Check the interface for nil before asserting: write the condition as 'err != nil && err.(MyErr).Code == 1'.","Verify assignment: ensure the interface variable was populated before the assertion point.","Use a comma-ok style check in real code (v, ok := x.(T)); in the debugger just print x first to see it is nil.","If inspecting a nil error, print it directly instead of asserting."],"exampleFix":"// before (breakpoint condition, err is nil interface)\ncond 1 err.(MyErr).Code == 1\n// error: interface conversion: error is nil, not MyErr\n// after\ncond 1 err != nil && err.(MyErr).Code == 1","handlingStrategy":"validation","validationCode":"// In any condition or expression, guard the nil interface first:\n// err != nil && err.(MyErr).Code == 1\n// CLI check: dlv> print err   // confirm non-nil before asserting","typeGuard":null,"tryCatchPattern":"res, err := scope.EvalExpression(assertExpr, cfg)\nif err != nil && strings.Contains(err.Error(), \"interface conversion:\") && strings.Contains(err.Error(), \"is nil\") {\n    // interface was nil; skip or handle nil case\n}","preventionTips":["always precede type assertions on interfaces with a nil check","print the interface first to see whether it holds a value","check that assignment happened before the assertion point","mirror comma-ok style (v, ok := x.(T)) in conditions"],"tags":["debugger","go","interface","nil","type-assertion"],"backgroundTag":"nil-interface-conversion","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}