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.
Locked
User avatar
owinsloe
Posts: 76
Joined: Tue Jul 10, 2012 10:37 am

Error object blocks with open brace on newline

Post by owinsloe » Tue Jun 18, 2019 2:00 pm

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
Joined: Thu Aug 18, 2011 4:56 am

Re: Error object blocks with open brace on newline

Post by davidc » Tue Jun 18, 2019 2:16 pm

Please try the latest service build of PowerShell Studio (v165). It should resolve this issue.
David
SAPIEN Technologies, Inc.

User avatar
owinsloe
Posts: 76
Joined: Tue Jul 10, 2012 10:37 am

Re: Error object blocks with open brace on newline

Post by owinsloe » Tue Jun 18, 2019 2:40 pm

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
Joined: Thu Aug 18, 2011 4:56 am

Re: Error object blocks with open brace on newline

Post by davidc » Tue Jun 18, 2019 2:51 pm

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: 76
Joined: Tue Jul 10, 2012 10:37 am

Re: Error object blocks with open brace on newline

Post by owinsloe » Tue Jun 18, 2019 3:32 pm

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
Joined: Thu Aug 18, 2011 4:56 am

Re: Error object blocks with open brace on newline

Post by davidc » Tue Jun 18, 2019 3:49 pm

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: 76
Joined: Tue Jul 10, 2012 10:37 am

Re: Error object blocks with open brace on newline

Post by owinsloe » Tue Jun 18, 2019 4:12 pm

Hmmmm, yes, that seems like a logical place. Thanks for the feedback David.
Cheers

Locked