{"action":"closed","issue":{"url":"https://api.github.com/repos/lukesampson/scoop/issues/339","labels_url":"https://api.github.com/repos/lukesampson/scoop/issues/339/labels{/name}","comments_url":"https://api.github.com/repos/lukesampson/scoop/issues/339/comments","events_url":"https://api.github.com/repos/lukesampson/scoop/issues/339/events","html_url":"https://github.com/lukesampson/scoop/issues/339","id":69170254,"number":339,"title":"All cmd shims created for Invoke-Build have a mistake","user":{"login":"nightroman","id":927533,"avatar_url":"https://avatars.githubusercontent.com/u/927533?v=3","gravatar_id":"","url":"https://api.github.com/users/nightroman","html_url":"https://github.com/nightroman","followers_url":"https://api.github.com/users/nightroman/followers","following_url":"https://api.github.com/users/nightroman/following{/other_user}","gists_url":"https://api.github.com/users/nightroman/gists{/gist_id}","starred_url":"https://api.github.com/users/nightroman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nightroman/subscriptions","organizations_url":"https://api.github.com/users/nightroman/orgs","repos_url":"https://api.github.com/users/nightroman/repos","events_url":"https://api.github.com/users/nightroman/events{/privacy}","received_events_url":"https://api.github.com/users/nightroman/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":8,"created_at":"2015-04-17T16:20:45Z","updated_at":"2015-04-19T03:58:01Z","closed_at":"2015-04-19T03:58:01Z","body":"The problem may be common for all shims created for PowerShell scripts. But I\r\nhave noticed it for Invoke-Build, so I explain it just for Invoke-Build.\r\n\r\nLet's take a look at *invoke-build.cmd*\r\n\r\n    @powershell -noprofile -ex unrestricted \"& '...\\scoop\\apps\\invoke-build\\2.9.14\\Invoke-Build.ps1' %*;exit $lastexitcode\"\r\n\r\nFor Invoke-Build the correct shim would be\r\n\r\n    @powershell -noprofile -ex unrestricted \"& '...\\scoop\\apps\\invoke-build\\2.9.14\\Invoke-Build.ps1' %*\"\r\n\r\nBecause when IB fails it throws a terminating error and PowerShell in this case\r\nexists with code 1. If IB works then PowerShell exits with code 0 itself. This\r\nis a normal scenario.\r\n\r\nBut the extra part `exit $lastexitcode` is a mistake and it may break things.\r\n\r\nSame as above, if IB fails it throws a terminating error. But this means that\r\nthe next statement `exit $lastexitcode` is not called at all. So it is not\r\nneeded.\r\n\r\nThe case when IB succeeds is more interesting. The automatic variable\r\n`$lastexitcode` is changed when a native application is called.\r\n\r\nIf no native command is called this variable is not even defined. In some cases\r\nthis will be treated as null and converted to 0. In other cases it may cause a\r\nfailure. Try to run this script in a fresh PowerShell session:\r\n\r\n    Set-StrictMode -Version 2\r\n    exit $LASTEXITCODE\r\n\r\nIt fails: *The variable '$LASTEXITCODE' cannot be retrieved because it has not been set.*\r\nSo that if a build script actually sets `Set-StrictMode -Version 2` and calls\r\nno native commands then it always fails due to the shim `exit $LASTEXITCODE`.\r\n\r\nThen, if a native command was called then its exit code tells nothing about IB\r\nsuccess or failure. Suppose a build script invoked by IB is\r\n\r\n    task copy {\r\n        exec {robocopy source destination /mir} (0..3)\r\n    }\r\n\r\n`robocopy` codes 0..3 are for success. Note that the function `exec` is told to\r\ntake this into account and to not fail on 0..3 codes. But PowerShell still sets\r\n`$lastexitcode` to one of this values when `robocopy` is called. And then the\r\nshim code uses it for exit. So in spite of the fact that IB succeeds the shim\r\nexists with non zero code. This is the mistake.\r\n\r\nAs the author of Invoke-Build, I am glad and proud it is noticed by *scoop*.\r\nOf course I would like Invoke-Build to be installed properly.\r\n"}}