{"record":{"id":"bb9b91e726986ea4","repo":"go-delve/delve","slug":"v","errorCode":null,"errorMessage":"%v","messagePattern":"%v","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"pkg/proc/eval.go","lineNumber":2363,"sourceCode":"\t}\n\n\tstack.push(xev.pointerToVariable())\n}\n\nfunc (v *Variable) pointerToVariable() *Variable {\n\tv.OnlyAddr = true\n\n\trv := v.newVariable(\"\", 0, godwarf.FakePointerType(v.DwarfType, int64(v.bi.Arch.PtrSize())), v.mem)\n\trv.Children = []Variable{*v}\n\trv.loaded = true\n\n\treturn rv\n}\n\nfunc constantUnaryOp(op token.Token, y constant.Value) (r constant.Value, err error) {\n\tdefer func() {\n\t\tif ierr := recover(); ierr != nil {\n\t\t\terr = fmt.Errorf(\"%v\", ierr)\n\t\t}\n\t}()\n\tr = constant.UnaryOp(op, y, 0)\n\treturn\n}\n\nfunc constantBinaryOp(op token.Token, x, y constant.Value) (r constant.Value, err error) {\n\tdefer func() {\n\t\tif ierr := recover(); ierr != nil {\n\t\t\terr = fmt.Errorf(\"%v\", ierr)\n\t\t}\n\t}()\n\tswitch op {\n\tcase token.SHL, token.SHR:\n\t\tn, _ := constant.Uint64Val(y)\n\t\tr = constant.Shift(x, op, uint(n))\n\tdefault:\n\t\tr = constant.BinaryOp(x, op, y)","sourceCodeStart":2345,"sourceCodeEnd":2381,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/proc/eval.go#L2345-L2381","documentation":"constantUnaryOp wraps go/constant's constant.UnaryOp and converts any panic it triggers into an error via fmt.Errorf(\"%v\", recover()). The message text is therefore whatever the go/constant runtime panicked with (e.g. an invalid unary operation on the constant's kind). It is a defensive wrapper so a malformed constant never crashes the debugger.","triggerScenarios":"Evaluating a unary expression (-x, +x, ^x, !x) at the debugger prompt where xv.Value is a constant.Value that go/constant cannot handle for that operator — e.g. `-\"string\"`, `^1.5`, or a constant produced from a corrupt/odd value read from debuggee memory.","commonSituations":"Applying numeric negation to a string constant, bitwise complement of a float, or exotic unary ops on values reconstructed from unusual memory states. Rare in normal use because earlier checks catch nil values and special floats.","solutions":["Check the operand type with `print x` and use an operator valid for it (negate ints/floats, `!` for bools, `^` for ints).","If the operand is a string, convert first (e.g. use `len(x)` or parse to a number) instead of applying arithmetic.","If the value itself looks corrupt, re-read it fresh (`print x`) or restart the session; the constant may come from a bad memory read.","Report persistent panics with the exact expression to go-delve/delve — the panic text comes from go/constant and may indicate an unhandled value kind."],"exampleFix":"// before\n(dlv) print -\"hello\"\n// panic converted to: <go/constant panic text>\n\n// after\n(dlv) print len(\"hello\") // string ops via valid builtins\n(dlv) print -n // unary minus only on numeric values","handlingStrategy":"try-catch","validationCode":"// Confirm the operand supports the unary op:\n(dlv) print x        // string? bool? use the right operator\n// numeric -> -x or ^x; bool -> !x","typeGuard":"func supportsUnaryMinus(v interface{}) bool {\n    switch reflect.TypeOf(v).Kind() {\n    case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,\n        reflect.Float32, reflect.Float64:\n        return true\n    }\n    return false\n}","tryCatchPattern":"// Delve already converts the panic to an error; on the client side (rpc2):\nres, err := client.EvalVariable(scope, expr, cfg)\nif err != nil && strings.Contains(err.Error(), \"invalid operation\") {\n    // re-issue with a corrected expression\n}","preventionTips":["Match the unary operator to the operand kind (numeric vs bool).","Never apply - or ^ to strings or bools.","Print the operand first if its kind is unclear."],"tags":["debugger","expression-evaluation","constant-arithmetic","unary-operator"],"backgroundTag":"invalid-unary-operation","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}