Skip to content

Remove unneeded catch/throw from 'mkdir' and 'oss' functions - #8425

Merged
Dongbo Wang (daxian-dbw) merged 1 commit into
PowerShell:masterfrom
daxian-dbw:mkdir
Dec 10, 2018
Merged

Remove unneeded catch/throw from 'mkdir' and 'oss' functions#8425
Dongbo Wang (daxian-dbw) merged 1 commit into
PowerShell:masterfrom
daxian-dbw:mkdir

Conversation

@daxian-dbw

@daxian-dbw Dongbo Wang (daxian-dbw) commented Dec 7, 2018

Copy link
Copy Markdown
Member

PR Summary

Remove unneeded catch/throw from 'mkdir' and 'oss' functions.

PR Checklist

@daxian-dbw Dongbo Wang (daxian-dbw) added the CL-CodeCleanup Indicates that a PR should be marked as a Code Cleanup change in the Change Log label Dec 8, 2018
@daxian-dbw
Dongbo Wang (daxian-dbw) merged commit 2a12fb5 into PowerShell:master Dec 10, 2018
@lzybkr

Copy link
Copy Markdown
Contributor

Dongbo Wang (@daxian-dbw) - sorry to have just noticed this - the seemingly unnecessary try/catch statements did serve a useful purpose at one point. I recall hating adding them, but IIRC, it improved error reporting in some useful way. Sorry, but I don't remember more than that though.

@iSazonov

Copy link
Copy Markdown
Collaborator

Does it update ScriptStackTrace in errorrecord?

@daxian-dbw

Copy link
Copy Markdown
Member Author

Jason Shirk (@lzybkr) Thanks for bringing up that context. Looks like those try/catch were added only for functions that uses SteppablePipeline. Might it be related to errors thrown from within the steppable pipeline? I will play with it a bit to see if I can find out why.

@daxian-dbw

Copy link
Copy Markdown
Member Author

The "better error reporting" might be related to PowerShell.AddScript(...).Invoke() doesn't throw on terminating error or exception, but instead keep the errors in the error stream.
Here is one example of that:

$ps = [powershell]::create()
$ps.AddScript(@'
 try {
     Get-Process -Invalid 42
 } catch {
     throw
 }
'@)
## try/catch/throw is needed for the exception to be thrown from $ps.invoke()
$ps.Invoke()

But it doesn't seem to be the exact reason for the try/catch/throw in the original mkdir and oss.
The following throws the exception even without the try/catch/throw in mkdir:

$ps = [powershell]::create()
$ps.AddScript("mkdir -Path blahhfe:\jkfjkjakfklajlkf -ea stop") > $null
$ps.Invoke()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-CodeCleanup Indicates that a PR should be marked as a Code Cleanup change in the Change Log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants