{"record":{"id":"b9fd96ba236ed77e","repo":"hashicorp/terraform","slug":"no-non-null-non-empty-string-arguments","errorCode":null,"errorMessage":"no non-null, non-empty-string arguments","messagePattern":"no non-null, non-empty-string arguments","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/lang/funcs/collection.go","lineNumber":173,"sourceCode":"\t},\n\tRefineResult: refineNotNull,\n\tImpl: func(args []cty.Value, retType cty.Type) (ret cty.Value, err error) {\n\t\tfor _, argVal := range args {\n\t\t\t// We already know this will succeed because of the checks in our Type func above\n\t\t\targVal, _ = convert.Convert(argVal, retType)\n\t\t\tif !argVal.IsKnown() {\n\t\t\t\treturn cty.UnknownVal(retType), nil\n\t\t\t}\n\t\t\tif argVal.IsNull() {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif retType == cty.String && argVal.RawEquals(cty.StringVal(\"\")) {\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\treturn argVal, nil\n\t\t}\n\t\treturn cty.NilVal, errors.New(\"no non-null, non-empty-string arguments\")\n\t},\n})\n\n// IndexFunc constructs a function that finds the element index for a given value in a list.\nvar IndexFunc = function.New(&function.Spec{\n\tParams: []function.Parameter{\n\t\t{\n\t\t\tName: \"list\",\n\t\t\tType: cty.DynamicPseudoType,\n\t\t},\n\t\t{\n\t\t\tName: \"value\",\n\t\t\tType: cty.DynamicPseudoType,\n\t\t},\n\t},\n\tType:         function.StaticReturnType(cty.Number),\n\tRefineResult: refineNotNull,\n\tImpl: func(args []cty.Value, retType cty.Type) (ret cty.Value, err error) {","sourceCodeStart":155,"sourceCodeEnd":191,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/lang/funcs/collection.go#L155-L191","documentation":"Thrown by `coalesce()` (CoalesceFunc) in its Impl when every variadic argument is either null or — for strings — an empty string. coalesce is defined to return the first non-null, non-empty-string value; if none qualify, it has nothing to return and errors. This is the 'no useful value found' terminal condition.","triggerScenarios":"All inputs are null or empty string: `coalesce(null, \"\", null)`. All optional variables unset and defaults empty.","commonSituations":"A lookup chain where every variable is unset and the final fallback is itself empty: `coalesce(var.a, var.b, \"\")`. Conditional config where all branches collapse to empty in the current workspace.","solutions":["Provide at least one argument that is non-null and (if string) non-empty.","Use a guaranteed non-empty literal fallback as the last argument.","If empty-string is legitimately acceptable, use `one(...)` or `try(...)` instead of coalesce, since coalesce intentionally excludes empty strings."],"exampleFix":"// before\nlocals { region = coalesce(var.region, var.default_region, \"\") }\n\n// after\nlocals { region = coalesce(var.region, var.default_region, \"us-east-1\") }","handlingStrategy":"fallback","validationCode":"# HCL: guarantee at least one non-empty fallback\nlocals { out = coalesce(var.a, var.b, \"__DEFAULT__\") }","typeGuard":"# HCL: prefer try() if empty-string/null are acceptable\nlocals { out = try(var.a, var.b, \"\") }","tryCatchPattern":null,"preventionTips":["Always end a coalesce() chain with a concrete non-empty literal.","If empty strings are valid, use `one()`/`try()` rather than coalesce (which excludes them by design).","Document the empty-string exclusion so contributors don't expect it."],"tags":["terraform","hcl","collection-functions","coalesce","null-handling"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}