{"record":{"id":"58ca261d83560276","repo":"dgraph-io/dgraph","slug":"expected-a-bool-but-got-v","errorCode":null,"errorMessage":"Expected a bool but got %v","messagePattern":"Expected a bool but got (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"dql/parser.go","lineNumber":341,"sourceCode":"\t\t\t\t\tValue: i,\n\t\t\t\t}, nil\n\t\t\t}\n\t\t}\n\tcase \"float\":\n\t\t{\n\t\t\tif i, err := strconv.ParseFloat(v.Value, 64); err != nil {\n\t\t\t\treturn types.Val{}, errors.Wrapf(err, \"Expected a float but got %v\", v.Value)\n\t\t\t} else {\n\t\t\t\treturn types.Val{\n\t\t\t\t\tTid:   types.FloatID,\n\t\t\t\t\tValue: i,\n\t\t\t\t}, nil\n\t\t\t}\n\t\t}\n\tcase \"bool\":\n\t\t{\n\t\t\tif i, err := strconv.ParseBool(v.Value); err != nil {\n\t\t\t\treturn types.Val{}, errors.Wrapf(err, \"Expected a bool but got %v\", v.Value)\n\t\t\t} else {\n\t\t\t\treturn types.Val{\n\t\t\t\t\tTid:   types.BoolID,\n\t\t\t\t\tValue: i,\n\t\t\t\t}, nil\n\t\t\t}\n\t\t}\n\tcase \"float32vector\":\n\t\t{\n\t\t\tif i, err := types.ParseVFloat(v.Value); err != nil {\n\t\t\t\treturn types.Val{}, errors.Wrapf(err, \"Expected a float32vector but got %v\", v.Value)\n\t\t\t} else {\n\t\t\t\treturn types.Val{\n\t\t\t\t\tTid:   types.VFloatID,\n\t\t\t\t\tValue: i,\n\t\t\t\t}, nil\n\t\t\t}\n\t\t}","sourceCodeStart":323,"sourceCodeEnd":359,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/dql/parser.go#L323-L359","documentation":"parseValue parses variables of type \"bool\" with strconv.ParseBool, which accepts only 1, t, T, TRUE, true, True, 0, f, F, FALSE, false, False. Any other string fails and is wrapped with 'Expected a bool but got %v'.","triggerScenarios":"Supplying a variable with Type \"bool\" whose Value is not one of strconv.ParseBool's accepted literals — e.g. \"$active\": \"yes\", \"on\", or \"True \" with trailing whitespace.","commonSituations":"Frontends sending \"yes\"/\"no\" or \"1\"/\"0\" from HTML inputs; language-serialized booleans like \"true\"/\"false\" from non-Go clients is fine but \"Yes\"/\"NO\" is not; trailing whitespace/newlines from form data.","solutions":["Normalize the value to \"true\" or \"false\" before adding it to the variables map","Trim whitespace from variable values sourced from user input or env","Map client booleans (yes/no, on/off) explicitly at the boundary","Pre-validate with strconv.ParseBool in the caller to catch bad values early"],"exampleFix":"// before\nvars := map[string]string{\"$active\": \"yes\"}\n// after\nvars := map[string]string{\"$active\": \"true\"}","handlingStrategy":"validation","validationCode":"if _, err := strconv.ParseBool(strings.TrimSpace(vars[\"$active\"])); err != nil {\n  return fmt.Errorf(\"$active must be a bool: %w\", err)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Normalize yes/no and on/off inputs to true/false at the boundary","Trim whitespace from form/env-derived variable values","Only send strconv.ParseBool-compatible literals (true/false/1/0/t/f)"],"tags":["dgraph","dql","variables","type-parsing","bool"],"backgroundTag":"query-variable-type-mismatch","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}