Skip to content

Improve error logging for exec of pscommands #598

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

Merged
merged 3 commits into from
Jan 6, 2018

Conversation

rkeithhill
Copy link
Contributor

This improves the output to the EditorServices.log file from:

1/4/2018 6:49:26 PM [ERROR] - Method "ExecuteCommand" at line 575 of C:\Users\Keith\GitHub\rkeithhill\PowerShellEditorServices\src\PowerShellEditorServices\Session\PowerShellContext.cs

    Execution completed with errors:

    You cannot call a method on a null-valued expression.
    You cannot call a method on a null-valued expression.

to

1/4/2018 6:49:26 PM [ERROR] - Method "ExecuteCommand" at line 575 of C:\Users\Keith\GitHub\rkeithhill\PowerShellEditorServices\src\PowerShellEditorServices\Session\PowerShellContext.cs

    Execution of command 'Import-Module - C:\Users\Keith\GitHub\rkeithhill\PowerShellEditorServices\module\PowerShellEditorServices\bin\Desktop\..\..\Commands\PowerShellEditorServices.Commands.psd1;' completed with errors:
    
    Error #1:
    You cannot call a method on a null-valued expression.
    ScriptStackTrace:
    at Register-EditorCommand<Process>, C:\Users\Keith\GitHub\rkeithhill\PowerShellEditorServices\module\PowerShellEditorServices\Commands\Public\CmdletInterface.ps1: line 51
    at <ScriptBlock>, C:\Users\Keith\GitHub\rkeithhill\PowerShellEditorServices\module\PowerShellEditorServices\Commands\Private\BuiltInCommands.ps1: line 1
    at <ScriptBlock>, C:\Users\Keith\GitHub\rkeithhill\PowerShellEditorServices\module\PowerShellEditorServices\Commands\PowerShellEditorServices.Commands.psm1: line 12
    Exception System.Management.Automation.RuntimeException: You cannot call a method on a null-valued expression.
       at CallSite.Target(Closure , CallSite , Object , Object )
       at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
       at System.Management.Automation.Interpreter.DynamicInstruction`3.Run(InterpretedFrame frame)
       at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
    
    Error #2:
    You cannot call a method on a null-valued expression.
    ScriptStackTrace:
    at Register-EditorCommand<Process>, C:\Users\Keith\GitHub\rkeithhill\PowerShellEditorServices\module\PowerShellEditorServices\Commands\Public\CmdletInterface.ps1: line 51
    at <ScriptBlock>, C:\Users\Keith\GitHub\rkeithhill\PowerShellEditorServices\module\PowerShellEditorServices\Commands\Private\BuiltInCommands.ps1: line 11
    at <ScriptBlock>, C:\Users\Keith\GitHub\rkeithhill\PowerShellEditorServices\module\PowerShellEditorServices\Commands\PowerShellEditorServices.Commands.psm1: line 12
    Exception System.Management.Automation.RuntimeException: You cannot call a method on a null-valued expression.
       at CallSite.Target(Closure , CallSite , Object , Object )
       at System.Management.Automation.Interpreter.DynamicInstruction`3.Run(InterpretedFrame frame)
       at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)

NOTE: While the two errors above "look" identical they actually arise from different lines of BuiltInCommands.ps1.

Copy link
Contributor

@daviwil daviwil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really helpful, thanks a bunch!

}

// We've reported these errors, clear them so they don't keep showing up.
this.powerShell.Streams.Error.Clear();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird, I could have sworn I added code for this in the past.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And there very well could be a better place to put this call. I contemplated clearing the error collection at the beginning of the method, before it runs the PSCommand. But I stuck with only clearing after reporting error message. BTW they weren't getting cleared. I kept seeing the same two import failures ($pseditor null) for every subsequent execution - profile loading, prompt eval, etc.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nah, this is the right place to do it. I just couldn't believe I hadn't actually added the code. Probably was in a branch somewhere that never got merged :/

@rkeithhill rkeithhill merged commit f29c9cf into master Jan 6, 2018
@rkeithhill rkeithhill deleted the rkeithhill/improve-pscommand-error-logging branch January 6, 2018 00:10
SeeminglyScience pushed a commit to SeeminglyScience/PowerShellEditorServices that referenced this pull request Feb 1, 2018
* Improve error logging for exec of pscommands

* Handle null ScriptStackTrace - not sure it's possible but just in case

* Tweak log output format and kick new build
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants