{"record":{"id":"844424532931fb85","repo":"go-delve/delve","slug":"interface-conversion-s-is-s-not-s","errorCode":null,"errorMessage":"interface conversion: %s is %s, not %s","messagePattern":"interface conversion: (.+?) is (.+?), not (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/proc/eval.go","lineNumber":2149,"sourceCode":"\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()\n\txev := stack.pop()\n\tif xev.Unreadable != nil {\n\t\tstack.err = xev.Unreadable\n\t\treturn\n\t}","sourceCodeStart":2131,"sourceCodeEnd":2167,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/proc/eval.go#L2131-L2167","documentation":"The mismatched-type variant of interface conversion failure: for 'x.(T)', if the assertion target type T (op.DwarfType) is non-nil and the dynamic type stored in the interface differs by name, evaluation fails with 'interface conversion: <iface name> is <dynamic type>, not <T>'. It mirrors Go's runtime panic but is produced at expression-evaluation time.","triggerScenarios":"Evaluating 'x.(T)' where the interface holds a concrete value of a different type than T — e.g. err.(MyErr) when err actually holds *errors.errorString or a different concrete type.","commonSituations":"Asserting the wrong concrete type when multiple types implement the same interface, asserting on error values that are wrapped (fmt.Errorf produces *fmt.wrapError, not MyErr), or version drift where the stored type changed.","solutions":["Print the interface first ('print x') to see the actual dynamic type, then assert that type.","Unwrap errors before asserting: check err.(*fmt.wrapError).Unwrap() or use errors.As in the program.","Use the correct concrete type in the assertion (pointer vs value matters: T vs *T).","Replace the assertion in a condition with a safe check like 'x != nil' plus the right type."],"exampleFix":"// before\ndlv> print err.(MyErr)\n// error: interface conversion: error is *fmt.wrapError, not main.MyErr\n// after\ndlv> print err.(*fmt.wrapError)   // or assert the actual dynamic type seen in 'print err'","handlingStrategy":"validation","validationCode":"// Print the interface to learn its dynamic type before asserting:\n// dlv> print x\n// then assert exactly the printed concrete type (including *T vs T).","typeGuard":null,"tryCatchPattern":"res, err := scope.EvalExpression(assertExpr, cfg)\nif err != nil && strings.Contains(err.Error(), \"interface conversion:\") && strings.Contains(err.Error(), \", not \") {\n    // dynamic type differs from asserted type; re-read err message for actual type\n}","preventionTips":["print the interface to discover the true dynamic type first","match pointer/value exactly (*MyErr vs MyErr)","unwrap wrapped errors before asserting your type","watch for type changes across library versions"],"tags":["debugger","go","interface","type-assertion","type-mismatch"],"backgroundTag":"interface-type-mismatch","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}