functions: Raise errors when +/- Infinity is returned from log or pow built-in functions - #39304
SarahFrench wants to merge 3 commits into
Conversation
7d40b0d to
115e42e
Compare
|
I'd be happy to hear what others think, but I think errors in these cases are more correct - terraform's focus is infrastructure, not maths, so I think it's valid to return errors instead of concepts (infinity, nan, etc). |
| if math.IsNaN(result) || math.IsInf(result, 0) { | ||
| return cty.UnknownVal(cty.String), fmt.Errorf("result is not a number") | ||
| } |
There was a problem hiding this comment.
Reviewer: Should +/- infinity return a different error? I could update this to return a different fmt.Errorf("result is not a finite number") or something.
| cty.NumberFloatVal(0), | ||
| cty.NumberFloatVal(10), | ||
| cty.NegativeInfinity, | ||
| false, |
There was a problem hiding this comment.
This old test case shows infinity being returned without an error, but I don't think this was part of an explicit decision to state that infinite values were valid returned values so we shouldn't be held back by it.
For me, the fact downstream code cannot process this value is a clear sign that raising an error instead is the correct behaviour.


Fixes #39292
This PR makes returning +/- Infinity from
logorpowbuilt-in functions invalid, and instead an error is raised.This PR is going to be left in draft until we confirm if the issue is a bug report or feature request.
Target Release
TBD
Rollback Plan
Changes to Security Controls
Are there any changes to security controls (access controls, encryption, logging) in this pull request? If so, explain.
CHANGELOG entry