Error object blocks with open brace on newline

Post feature requests, product enhancement ideas, and other product-specific suggestions here. Do not post bug reports.
Forum rules
Do not post any licensing information in this forum.
This topic is 4 years and 9 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
owinsloe
Posts: 161
Last visit: Mon Mar 18, 2024 12:33 pm
Been upvoted: 1 time

Error object blocks with open brace on newline

Post by owinsloe »

Product: PowerShell Studio 2019 (64 Bit)
Build: v5.6.160
OS: Windows 10 Enterprise (64 Bit)
Build: v10.0.17763.0

Hi guys, A slightly annoying issue with powershell is that it does not recognize the object script blocks with an open brace on a newline. I am in the habit (rightly or wrongly) of placing braces on a newline (except under these situations) and occasionally I forget.

PSS does not see this as an error and the script packages up ok but when you go to run it you get that awesome blocking user input request

cmdlet ForEach-Object at command pipeline position 1
Supply values for the following parameters:

eg.
This is good...
(1..3) | ?{ $_ -eq 1 }

This is NOT...
(1..3) | ?
{
$_ -eq 1
}

Maybe a future PS build will handle this but in the meantime would it be possible for PSS to detect this situation as an ERROR?

Thanks
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Error object blocks with open brace on newline

Post by davidc »

Please try the latest service build of PowerShell Studio (v165). It should resolve this issue.
David
SAPIEN Technologies, Inc.
User avatar
owinsloe
Posts: 161
Last visit: Mon Mar 18, 2024 12:33 pm
Been upvoted: 1 time

Re: Error object blocks with open brace on newline

Post by owinsloe »

Product: PowerShell Studio 2019 (64 Bit)
Build: v5.6.165
OS: Windows 10 Enterprise (64 Bit)
Build: v10.0.17763.0

Hi David,
That would have been amazing (and coincidental) had it resolved the issue, but it did not.

I pasted this into a new script and run through the PSS editor and it raised the smdlet where-object user input dialog and the editor did not indicate this was a problem by display a red bang.

(1 .. 3) | Where-Object
{
$_ -eq 1
}
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Error object blocks with open brace on newline

Post by davidc »

My apologies, I misunderstood the request. I thought you were reporting a formatting issue where PowerShell Studio was placing the opening bracket on a new line.

As for errors, it is PowerShell engine that reports the syntax errors. Even though your intention was for the script block to be part of the Where-Object command, according to PowerShell, this is a valid statement and there is nothing syntactically wrong with it.
David
SAPIEN Technologies, Inc.
User avatar
owinsloe
Posts: 161
Last visit: Mon Mar 18, 2024 12:33 pm
Been upvoted: 1 time

Re: Error object blocks with open brace on newline

Post by owinsloe »

David,
No problem and understand what you are saying. Yes, syntax wise, it's fine, but if your intention is to have a non blocking script to run that does not require user input then this unexpected behavior can be very frustrating.

Maybe if I try a new approach, rather than PSS reporting this as an error, perhaps it could raise a warning. Something along the lines of...

"Placing a script block following an object statement on a newline will cause Powershell to request user input. Are you sure that you wish to do this?".

...or something along those lines. I know it's not really the responsibility of PSS but it would be a nice feature (perhaps an optional feature)

Thanks
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Error object blocks with open brace on newline

Post by davidc »

I understand and thank you for the suggestion. I wonder if this would make more sense as a PSScriptAnalyzer rule.
David
SAPIEN Technologies, Inc.
User avatar
owinsloe
Posts: 161
Last visit: Mon Mar 18, 2024 12:33 pm
Been upvoted: 1 time

Re: Error object blocks with open brace on newline

Post by owinsloe »

Hmmmm, yes, that seems like a logical place. Thanks for the feedback David.
Cheers
This topic is 4 years and 9 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked