-
Notifications
You must be signed in to change notification settings - Fork 191
CI: Report full stack trace if ScriptAnalyzer throws an error and improve ScriptAnalyzer installation to not skip publisher and check and not allow clobber #236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Thanks @bergmeister -- I don't want to merge that change in because I very specifically want to have this run on PS5, but I will kick off a few rounds of CI to see if we can hit the error within the context of this PR. |
/azp run PowerShellForGitHub-CI |
Azure Pipelines successfully started running 1 pipeline(s). |
@HowardWolosky Ok, but even if it happens again, just the default error message won't be enough, I need the full stack trace. |
/azp run PowerShellForGitHub-CI |
Commenter does not have sufficient privileges for PR 236 in repo microsoft/PowerShellForGitHub |
/azp run PowerShellForGitHub-CI |
Azure Pipelines successfully started running 1 pipeline(s). |
Thanks! |
/azp run PowerShellForGitHub-CI |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run PowerShellForGitHub-CI |
Azure Pipelines successfully started running 1 pipeline(s). |
displayName: 'Install PSScriptAnalyzer' | ||
|
||
- powershell: | | ||
$results = Invoke-ScriptAnalyzer -Path ./ –Recurse | ||
$results = try { Invoke-ScriptAnalyzer -Path ./ –Recurse -ErrorAction Stop } catch { $StackTrace; throw } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that this change will prevent us from getting our published NUnit results. If that's the case, we wouldn't want to merge this in. I can run this in CI a few more times though to see if we can catch the ScriptAnalyzer bug though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you think it would prevent that? The point of re-throwing is to alert you that something bad happened during analysis so that you can then report the stack trace so that we can investigate further.
Right now, if that sporadic error happened in master, your build would be red as well, therefore I am not changing behaviour, I am only adding the additional information, which is the stack trace
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be my misunderstanding then of how Invoke-ScriptAnalyzer
behaves with -ErrorAction -Stop
. I was under the impression that if it had any failures and -ErrorAction Stop
was set, it would throw, causing any statements following it to not be executed.
I just tried tried to verify this myself locally though, and it looks like my understanding there was wrong. Can you just clarify under what scenarios Invoke-ScriptAnalyzer -ErrorAction Stop
will result in an exception being thrown ?
Right now, if that sporadic error happened in master.
It has happened in PR CI builds as well. There isn't anything special about the master builds vs the CI builds.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. Let me explain a few things first:
-ErrorAction
is a so called common parameter and not specific to PSScriptAnalyzer. Binary cmdlets likeInvoke-ScriptAnalyzer
or advanced script functions (i.e. a function that is decorated with the[CmdletBinding()]
attribute) automatically inherit those common parameters that the PowerShell engine handles/provides.- There are 2 types of errors in PowerShell: terminating and non-terminating. The idea is that when an operation fails when processing pipeline input and one input fails, one usually does not want pipeline processing to stop because of that. This is important to know because:
- A
catch
block only catches terminating error and I know from experience that leaked exceptions from inside PSScriptAnalyzer are treated as non-terminating errors. - Therefore we would not be able to catch that exception, which you sporadically observe just by doing
try { Invoke-ScriptAnalyzer } catch { 'hello' }
. - You might be asking why the build is red then. This is because CI environment providers detect when a non-terminating errors occurred after a line has finished executing and fail the build as it is indication that something went wrong, which is right.
- Now, in order to catch and report the exception that happens, we use
-ErrorAction Stop
, as this tells PowerShell to stop processing when any type of error occurs and treat them as terminating errors. This essentially allows us to get into thecatch
block and the reason to use-ErrorAction Stop
.
Therefore to conclude, this PR does not change the behaviour, it only logs out the stacktrace additionally when an error occurs. Changing it to not re-throw to avoid the build going red would not be good because ScriptAnalyzer's analysis would be incomplete and we want to be alerted of the error and report it the next time it happens. Therefore my suggestion is to just merge the PR and report the stack trace back to me the next time it happens so that we can look into fixing it in the next version
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good -- I appreciate the thorough response/help here. Getting this merged-in now and will report back the stack trace should it happen again.
…l one from PowerShell itself
/azp run PowerShellForGitHub-CI |
Azure Pipelines successfully started running 1 pipeline(s). |
@bergmeister - We had a hit last night, but I don't see anything useful coming out of it
|
Hmm, interesting. Not sure why we didn't get the stack trace from
In order to help us understand better why we don't get more information, we could add a bit more logging into the catch block so that we know a bit more. @TylerLeonhardt This is a good example of why I don't need/want to attach to Azure DevOps agents, I rather want basic logging such as:
|
@bergmeister, these intermittent ScriptAnalyzer errors keep happening and are still not producing any stack trace output. It doesn't look like the
Example build log here: https://dev.azure.com/ms/PowerShellForGitHub/_build/results?buildId=129530&view=logs&j=a5e52b91-c83f-5429-4a68-c246fc63a4f7&t=c9cf2fd0-7e3a-5695-1b5f-45f64bd81b9a |
Description
PR #221 reported that this repo causes PSScriptAnalyzer to sporadically throw an error.
In order to report the full error needed for analysis, report the full stack trace. In order to make this easier, I make the build run on PowerShell 7 instead, which has the built-in
Get-Error
cmdlet, which simplifies the reporting.Checklist
is reporting back clean.