Skip to content

Custom prompt causes extension to fail to load #1857

Closed
@bluekeys

Description

@bluekeys

System Details

System Details Output

### VSCode version: 1.33.0 0dd516dd412d42323fc3464531b1c715d51c4c1a x64

### VSCode extensions:
bubersson.theme-hop-light@0.0.4
christian-kohler.npm-intellisense@1.3.0
dbaeumer.vscode-eslint@1.8.2
EditorConfig.EditorConfig@0.13.0
eg2.vscode-npm-script@0.3.5
Fr43nk.seito-openfile@1.8.5
johnpapa.vscode-peacock@2.0.1
johnpapa.winteriscoming@0.9.0
mikestead.dotenv@1.0.1
ms-mssql.mssql@1.5.0
ms-vscode.csharp@1.18.0
ms-vscode.powershell@1.12.0
msjsdiag.debugger-for-chrome@4.11.3
octref.vetur@0.18.1
PeterJausovec.vscode-docker@0.6.1
PKief.material-icon-theme@3.7.0
redhat.vscode-xml@0.5.1
Shan.code-settings-sync@3.2.8
vscodevim.vim@1.4.0
vscoss.vscode-ansible@0.5.2


### PSES version: 1.12.0.0

### PowerShell version:

Name                           Value
----                           -----
PSVersion                      5.1.17134.112
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.17134.112
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Issue Description

I am experiencing a problem with my custom prompt causing the extension to fail to load.

The prompt is configured in

$HOME\Documents\WindowsPowerShellMicrosoft.Powershell_profile.ps1

The offending code is

function Write-BranchName () {
  try {
      $branch = git rev-parse --abbrev-ref HEAD

      if ($branch -eq "HEAD") {
          # we're probably in detached HEAD state, so print the SHA
          $branch = git rev-parse --short HEAD
          Write-Host " ($branch)" -ForegroundColor "red"
      }
      else {
          # we're on an actual branch, so print it
          Write-Host " ($branch)" -ForegroundColor "blue"
      }
  } catch {
      # we'll end up here if we're in a newly initiated git repo
      Write-Host " (no branches yet)" -ForegroundColor "yellow"
  }
}

function prompt {
  $base = "PS "
  $path = "$($executionContext.SessionState.Path.CurrentLocation)"
  $userPrompt = "$('>' * ($nestedPromptLevel + 1)) "

  Write-Host "`n$base" -NoNewline

  if (Test-Path .git) {
      Write-Host $path -NoNewline -ForegroundColor "green"
      Write-BranchName
  }
  else {
      # we're not in a repo so don't bother displaying branch name/sha
      Write-Host $path -ForegroundColor "green"
  }

  return $userPrompt
}

To reproduce, just add the code to your profile and start vscode.

Expected Behaviour

Powershell session should start and my sweet, custom prompt should show.

Actual Behaviour

"The Powershell session has terminated due to an error, would you like to restart it": Source: Powershell (Extension) - loop ad infnitum

Attached Logs

2019-04-09 10:02:23.562 [ERROR] tid:4 in 'OnListenTaskCompleted' C:\PowerShellEditorServices\src\PowerShellEditorServices.Protocol\MessageProtocol\ProtocolEndpoint.cs: line 391
    ProtocolEndpoint message loop terminated due to unhandled exception:
    
    System.AggregateException: One or more errors occurred. ---> System.NotSupportedException: The given path's format is not supported.
       at System.Security.Permissions.FileIOPermission.EmulateFileIOPermissionChecks(String fullPath)
       at System.Security.Permissions.FileIOPermission.QuickDemand(FileIOPermissionAccess access, String fullPath, Boolean checkForDuplicates, Boolean needFullPath)
       at Microsoft.PowerShell.EditorServices.Workspace.ResolveFilePath(String filePath)
       at Microsoft.PowerShell.EditorServices.Workspace.GetFile(String filePath)
       at Microsoft.PowerShell.EditorServices.CodeLenses.CodeLensFeature.<HandleCodeLensResolveRequest>d__6.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol.MessageDispatcher.<DispatchMessage>d__7.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol.ProtocolEndpoint.<ListenForMessages>d__36.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Microsoft.PowerShell.EditorServices.Utility.AsyncContext.Start(Func`1 asyncMainFunc, ILogger logger)
       at System.Threading.Tasks.Task.Execute()
       --- End of inner exception stack trace ---
    ---> (Inner Exception #0) System.NotSupportedException: The given path's format is not supported.
       at System.Security.Permissions.FileIOPermission.EmulateFileIOPermissionChecks(String fullPath)
       at System.Security.Permissions.FileIOPermission.QuickDemand(FileIOPermissionAccess access, String fullPath, Boolean checkForDuplicates, Boolean needFullPath)
       at Microsoft.PowerShell.EditorServices.Workspace.ResolveFilePath(String filePath)
       at Microsoft.PowerShell.EditorServices.Workspace.GetFile(String filePath)
       at Microsoft.PowerShell.EditorServices.CodeLenses.CodeLensFeature.<HandleCodeLensResolveRequest>d__6.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol.MessageDispatcher.<DispatchMessage>d__7.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol.ProtocolEndpoint.<ListenForMessages>d__36.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Microsoft.PowerShell.EditorServices.Utility.AsyncContext.Start(Func`1 asyncMainFunc, ILogger logger)
       at System.Threading.Tasks.Task.Execute()<---

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions