Powershell: Write-Error can sometimes include more output than is wanted

Created on 2 Mar 2018  路  11Comments  路  Source: PowerShell/PowerShell

if you invoke a script block which has write-error, you get the entire contents of the scriptblock in the write-error output. It would be better if it were only the write-error line, and the line of the scriptblock which had the error

Steps to reproduce

PS> $sb = [scriptblock]::Create("get-date
(get-location).path
write-error badthing")                                                                                                                   
PS> & $sb                                                                                                                                                                                                                                                                               

Expected behavior

Friday, March 2, 2018 11:37:45 AM                                                                                                           
/tmp
write-error badthing : badthing
At line:3 char:1
+ & $sb
+ ~~~~~
+ CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException


Actual behavior

Friday, March 2, 2018 11:37:45 AM                                                                                                           
/tmp
get-date
(get-location).path
write-error badthing : badthing
At line:1 char:1
+ & $sb
+ ~~~~~
+ CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException


note that the entire scriptblock contents has been emitted. This could be ridiculously large.

Environment data

> $PSVersionTable
Name                           Value                                                                                                       
----                           -----                                                                                                       
PSVersion                      6.0.1                                                                                                       
PSEdition                      Core                                                                                                        
GitCommitId                    v6.0.1                                                                                                      
OS                             Darwin 17.4.0 Darwin Kernel Version 17.4.0: Sun Dec 17 09:19:54 PST 2017; root:xnu-4570.41.2~1/RELEASE_X8...
Platform                       Unix                                                                                                        
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                     
PSRemotingProtocolVersion      2.3                                                                                                         
SerializationVersion           1.1.0.1                                                                                                     
WSManStackVersion              3.0       
Area-Cmdlets-Core Issue-Enhancement Resolution-Won't Fix

All 11 comments

Thanks for opening this issue.

This is a problem on PS 5.1 on Windows and should also be fixed here too.

This happens even without scriptblock.

image

Hi JamesWTruher I will fix this issue.
Please assign this issue to me..

@ashok777hb No need for any assignment,

  • Fork PowerShell repo --> Create a patch branch --> Fix it --> Test it--> do a PR.

@ashok777hb ,
Are you working on this one? Also, I am not sure how exactly this works. If you merge a fix, we would still have to wait for a new version of deployable PowerShell such as 5.2. Correct?

This repo does not typically work on Windows PowerShell 5.1 features. The majority of merged code will be included in a future release such as PowerShell Core 6.2.

Some items that are a matter of security or other important features may be occasionally backported by the PS team and rolled into 5.1 in a Windows Update security patch, from what I've heard.

@vexx32 that is mostly correct, however, no new features are being backported to 5.1. The code base has diverged enough that any backports have become big work items.

I am working on this.. I will update by next week..

Hi @ashok777hb how was your week (and year)? This bug still seems to be there :(

This is already fixed in ConciseView, I would expect any changes would be for NormalView

Now that we have ConciseView, I don't think we'll make changes to NormalView

Was this page helpful?
0 / 5 - 0 ratings