-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🐛 Do not return the type of the predicate for if blocks #3412
Conversation
i haven't been able to get this to fail with the mock tests. It also doesn't seem to happen all the time. For example, an error in |
I think I kind of understand it in a hand wavy way. In the case of As an aside, I don't really think we need |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for analyzing this, I can see that return types inside of the conditionals that are failing can lead to the whole thing to fall apart. Let's get this merged first to move forward.
Let's come up with a decision around how we want to handle errors in conditionals. I'm somewhat in favor of treating them as Another approach could be to iterate all conditional branches to see if a truthy branch is found. If none is encountered, it could still opt to expose errors (as seen in other frameworks). The downside with this approach is that it will set user expectations to see errors, but all of a sudden hide them if a truthy branch is found. Ultimately it's a decision about the behavior of this code. |
When there were errors, `ifCallV2` would return the type of the predicate for the result of the if block. That becomes problematic for a query like the following: ``` if (file('/etc/amazon/').exists) { return "AWS" } else if ( users.any( name == 'ec2-user' || name == 'ec2-instance-connect' ) ) { return "AWS" } else if ( machine.baseboard.manufacturer == 'Amazon EC2') { return "AWS" } else if ( asset.platform == "cos" ) { return "GCP" } else if ( file('/etc/google_instance_id').exists ) { return "GCP" } else if ( file('/var/lib/waagent/').exists ) { return "Azure" } else if ( file('/var/lib/dhcp/dhclient.enp1s0.leases').exists && file('/var/lib/dhcp/dhclient.enp1s0.leases').content.lines.contains( /unknown-245/ ) ) { return "Azure" } else { return "Unknown" } ``` If you cannot run `machine.baseboard.manufacturer`, for example if you're not root, an error is returned. The type of the result is boolean, when it should be string. You then get a message like the following: ``` failed to send datapoints error="1 error occurred:\n\t* failed to store data for \"HTCzrF9d2vMJ1iUZsoMcMwaC8XQ7bvQE5nLxC0I5cSBlLXawpmn74WyIEaTgXuUmz/C5iRSeedT3eBg9h6xx8A==\", types don't match: expected string, got bool\n\n" ```
f00244e
to
b2e43f2
Compare
Test Results2 829 tests ±0 2 828 ✅ ±0 1m 15s ⏱️ -7s Results for commit b2e43f2. ± Comparison against base commit 7e8f0bd. This pull request removes 6 and adds 6 tests. Note that renamed tests count towards both.
|
When there were errors,
ifCallV2
would return the type of the predicate for the result of the if block.That becomes problematic for a query like the following:
If you cannot run
machine.baseboard.manufacturer
, for example if you're not root, an error is returned. The type of the result is boolean, when it should be string. You then get a message like the following: