{"record":{"id":"57cfbf3aa9fab638","repo":"dgraph-io/dgraph","slug":"wrong-type-v-encountered-for-func-exp","errorCode":null,"errorMessage":"Wrong type %v encountered for func exp","messagePattern":"Wrong type (.+?) encountered for func exp","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"query/aggregator.go","lineNumber":460,"sourceCode":"\n\tcase DEFAULT:\n\t\treturn errors.Errorf(\"Wrong type %v encountered for func ln\", a.Tid)\n\t}\n\treturn nil\n}\n\nfunc applyExp(a, res *types.Val) error {\n\tvBase := getValType(a)\n\tswitch vBase {\n\tcase INT:\n\t\tres.Value = math.Exp(float64(a.Value.(int64)))\n\t\tres.Tid = types.FloatID\n\n\tcase FLOAT:\n\t\tres.Value = math.Exp(a.Value.(float64))\n\n\tcase DEFAULT:\n\t\treturn errors.Errorf(\"Wrong type %v encountered for func exp\", a.Tid)\n\t}\n\treturn nil\n}\n\nfunc applyNeg(a, res *types.Val) error {\n\tvBase := getValType(a)\n\tswitch vBase {\n\tcase INT:\n\t\t// -ve of math.MinInt64 is evaluated as itself (due to overflow)\n\t\tif a.Value.(int64) == math.MinInt64 {\n\t\t\treturn ErrorIntOverflow\n\t\t}\n\t\tres.Value = -a.Value.(int64)\n\t\tres.Tid = types.IntID\n\n\tcase FLOAT:\n\t\tres.Value = -a.Value.(float64)\n\t\tres.Tid = types.FloatID","sourceCodeStart":442,"sourceCodeEnd":478,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/query/aggregator.go#L442-L478","documentation":"The `exp` unary function computes e^x only for INT, FLOAT, and BIGFLOAT inputs. If the argument's type ID is anything else (DEFAULT, string, bool, dateTime, etc.), applyExp returns this error naming the unsupported type. Like the other math aggregators it relies on matchType to coerce types first, so this fires only when no numeric coercion was possible.","triggerScenarios":"A query like math exp(v) where v binds to a non-numeric value: string predicate, boolean, dateTime, or an untyped/default value that matchType could not convert.","commonSituations":"Feeding exp() a uid variable or count alias mismatch; predicate schema changed from float to another type; using exp on a facet stored as string.","solutions":["Verify the input predicate/variable is int or float typed in the schema","Cast or transform the value to a number before applying exp (e.g. via since() which returns float, or arithmetic)","Remove or replace non-numeric arguments in the math expression","Test the query with a literal (math exp(1)) to isolate which variable carries the bad type"],"exampleFix":"// before\n\"math exp(name)\"\n// after\n\"math exp(age)\"","handlingStrategy":"type-guard","validationCode":"const t = schemaOf('score');\nif (!['int','float'].includes(t)) throw new Error('exp requires numeric predicate');","typeGuard":"function isNumber(v) { return typeof v === 'number'; }","tryCatchPattern":"try {\n  return await txn.query(q);\n} catch (e) {\n  if (String(e).includes('func exp')) throw new Error('exp operand must be numeric: ' + e);\n  throw e;\n}","preventionTips":["Confirm schema type of every predicate used in math exp","Never pass uid or datetime values to exp","Unit-test math expressions with representative data","Avoid dynamically generated expressions without type checks"],"tags":["dgraph","query","math-function","type-mismatch"],"backgroundTag":"math-function-invalid-type","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}