Skip to content
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

Warning is not a valid log level in Start-EditorServices.ps1 #894

Closed
allthejunkfood opened this issue Mar 14, 2019 · 6 comments
Closed

Warning is not a valid log level in Start-EditorServices.ps1 #894

allthejunkfood opened this issue Mar 14, 2019 · 6 comments

Comments

@allthejunkfood
Copy link

System Details

System Details Output


Issue Description

Powershell Integrated Console Start-EditorServices terminated with Exit code: 1
Then the language Service could not be started

Expected Behaviour

...I mean... It should just run...

What I did to fix it

Just as an FYI: I imagine that this will only help those that it affects directly (or fall under these circumstances)
Happened to notice that when VS code would boot up, there would be some red text at the powershell screen. It would quickly go away and then start the "Exit Code: 1" nonsense. (Hooray for useful exit codes! Hooray for School!)
What was the error? Well you have to hit printscreen to capture it at VScode startup but here was mine:
C:\users<REDACTED>.vscode\extensions\ms-vscode.powershell-1.11.0\modules\PowerShellEditorServices\Start-EditorServices.ps1: Cannot validate argument on parameter 'LogLevel'. The argument "warning" does not belong to the set "Diagnostic,Normal,Verbose,Error" specified by the ValidateSet attribute. Supply an argument that is in the set and then try the command again.
There was some more error jazz, but for the most part, useless info.

To fix that -
Add
"Warning"

[ValidateSet("Normal", "Verbose", "Error", "Diagnostic","Warning")]
$LogLevel = "Normal",

to the two following files:

C:\Users<MonkeyTown>.vscode\extensions\ms-vscode.powershell-1.11.0\modules\PowerShellEditorServices\Start-EditorServices.ps1

and

C:\Users<MonkeyTown>.vscode\extensions\ms-vscode.powershell-1.11.0\modules\PowerShellEditorServices\PowerShellEditorServices.psm1

Whamo blamo... new error.

rinse repeat (exit vscode, and reopen printscreen)
Error: Start-EditorServices.ps1 cannot be loaded the contents of C:\Users<MonkeyTown>.vscode\extensions\ms-vscode.powershell-1.11.0\modules\PowerShellEditorServices\Start-EditorServices.ps1 might have been changed....

CHANGED

For mo' better security, I have AllSigned scripts turned on. What does that mean now? Hammer Time.
Go through and with a code signing certificate sign every (I mean every) ps1 psm1 psd1 with my local trusted certificate. Cause why? Cause I now own all those files and they are trusted by me.

For this portion, if you don't have a code signing certificate, either public or privately issued. Get one. Private? use PKI.
Added Bonus, here is a code signing script I Frankensteined:

Function Sign-Script {
<#

    .DESCRIPTION
    Sign-Script will prompt to select one or more PowerShell Scripts that need to be signed. 

    .EXAMPLE
    sign-script -script c:\users\example.ps1
    sign-script
                
#>
[CmdletBinding()]
Param (
    [Parameter(Mandatory=$False)]
    [string]$script
    )

if($script -match ".ps1" -or ".ps.1"){
    $cert = (Get-ChildItem Cert:\CurrentUser\my -CodeSigningCert)[0]
    Set-AuthenticodeSignature $script -Certificate $cert -TimestampServer http://timestamp.verisign.com/scripts/timstamp.dll
}
else{
Add-Type -AssemblyName System.Windows.Forms
$FileBrowser = New-Object System.Windows.Forms.OpenFileDialog -Property @{
Multiselect = $true # Multiple files can be chosen
}

[void]$FileBrowser.ShowDialog()

$path = $FileBrowser.FileNames;
$cert = (Get-ChildItem Cert:\CurrentUser\my -CodeSigningCert)[0]
If($FileBrowser.FileNames -like "*\*") {

    # Do something before work on individual files commences
    $FileBrowser.FileNames #Lists selected files (optional)
	
    foreach($file in Get-ChildItem $path){
    Get-ChildItem ($file) |
        ForEach-Object {
        $confirmation = read-host "Press 'Y' to confirm signature"
        if ($confirmation -eq 'y'){

        Set-AuthenticodeSignature $file -Certificate $cert -TimestampServer http://timestamp.verisign.com/scripts/timstamp.dll
        }
        }
    }

I hope this helps someone at some point.

Attached Logs

Follow the instructions in the troubleshooting docs
about capturing and sending logs.

@TylerLeonhardt
Copy link
Member

@allthejunkfood feel free to contribute the addition of the Warning log level! It's here:

https://github.com/PowerShell/PowerShellEditorServices/blob/master/module/PowerShellEditorServices/Start-EditorServices.ps1#L50

@TylerLeonhardt TylerLeonhardt changed the title Powershell Integrated Console Start-EditorServices terminated with exit code: 1 Warning is not a valid log level in Start-EditorServices.ps1 Mar 14, 2019
@Benny1007
Copy link
Contributor

Should this issue be moved to the PowerShellEditorServices repo then?

@rkeithhill
Copy link
Collaborator

rkeithhill commented Mar 26, 2019

I probably should be. @TylerLeonhardt or @rjmholt should have the ability to move the issue. But more important is to get a PR in to add support for Warning.

@TylerLeonhardt TylerLeonhardt transferred this issue from PowerShell/vscode-powershell Mar 26, 2019
@TylerLeonhardt
Copy link
Member

transfered :)

@Benny1007
Copy link
Contributor

Benny1007 commented Mar 27, 2019

Pull request #895 raised.

@corbob
Copy link
Contributor

corbob commented May 14, 2019

Looks like the PR didn't specify that it fixes this issue... Should this be closed now?

/cc @TylerLeonhardt @rjmholt

@rjmholt rjmholt closed this as completed May 14, 2019
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

No branches or pull requests

6 participants