When is a boolean not a boolean?

Can someone explain why this is evaluating like this? I want to trap the error in case the registry key doesn’t exist, so I’m using the inline pipe operator, but the results are perplexing:

Q: value "fDenyTSConnections" of key "HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server" of registry
A: 1
I: singular registry key value

Q: (value "fDenyTSConnections" of key "HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server" of registry as string) = "1"
A: True
I: singular boolean

Q: False
A: False
I: singular boolean

Q: ( (value "fDenyTSConnections" of key "HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server" of registry as string) = "1" | False )
E: Incompatible types.

Q: ( ((value "fDenyTSConnections" of key "HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server" of registry as string) = "1") as string | "False" )
A: True
I: singular string

Q: ( ((value "fDenyTSConnections" of key "HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server" of registry as string) = "1") as string | "False" ) = "True"
A: True
I: singular boolean

So, in order to end up with a boolean, I have to turn a boolean into a string and compare it to the string “True”? Are booleans not allowed as return values in pipe operations? I cannot find the documentation on error trapping to try to verify this on my own.

– John

Try the following:

(((value "fDenyTSConnections" of key "HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server" of registry as string) = "1") | False)

The issue here was a question of order of operations.

2 Likes

So, what was being pipe-compared before the addition of another pair of parens? Just the "1" | False part? O_o

Essentially, yes. It may not be easily evident, but the Incompatible Types was a clue. You can actually visualize this a bit better in a graphical tab of the Fixlet Debugger:

image

vs.

image

All that said, I do think we need to work on improving error messaging and providing better error/troubleshooting guidance in our tooling :slight_smile:

2 Likes

Maaaan…I keep forgetting that’s there. Thanks, @Aram! :slight_smile:

1 Like

Something else to consider. In such cases, if there are questions about how relevance will handle a situation, it can help to break it down into simpler examples. For instance, if it’s unclear whether or not the pipe operator would accept a boolean value, you could try something like:

Q: true | false
A: True
I: singular boolean

Q: false | true
A: False
I: singular boolean