oh-my-posh: Loading profile in VsCode PowerShell Extension leads to error in custom key handler
Code of Conduct
- I agree to follow this project’s Code of Conduct
What happened?
Hello,
have recently updated to v12.0.1 to see if this still occurs and it does:
D:\Code\Personal> oh-my-posh init pwsh --config $UserPsScripts\ParagnosterPlus2.omp.json | Invoke-Expression
[2022-10-08 12:59:19]❯ An exception occurred in custom key handler, see $error for more information: Object reference not set to an instance of an object.
Once I load Oh-my-Posh, the Terminal provided by the PowerShell Extension Module throws this error.
The normal VsCode terminal does not exhibit this behavior. If I enable “Use Legacy Read Line” (I am advised that this isn’t recommended) in the PowerShell Extension, it also does not occur.
I think my (recently updated) theme is causing this, but which part may it be?
Recent changes:
- Added a second line
- Added Sysinfo
- Enabled TransientPrompt (which does lead to lingering text when copy/pasting muli-line text btw)
Theme
I have created a personal theme with all I’d need and like to see. Intially based on Paragon and Agnoster Plus, but v2 now incorporates other elements as well
This issue does not occur with ParagnosterPlus v1
{
"$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
"blocks": [{
"alignment": "left",
"segments": [{
"Enabled": false,
"foreground": "#1BD760",
"properties": {
"paused_icon": "\uf8e3 ",
"playing_icon": "\ue602 ",
"stopped_icon": "\uf04d ",
"track_separator": " - "
},
"style": "plain",
"template": "{{ .Icon }}{{ if ne .Status \"stopped\" }}{{ .Artist }} - {{ .Track }}{{ end }} ",
"type": "spotify"
}],
"type": "prompt"
},
{
"alignment": "right",
"segments": [{
"foreground": "#91ddff",
"style": "plain",
"template": " \uf85a {{ round .PhysicalPercentUsed .Precision }}% ",
"type": "sysinfo"
},
{
"foreground_templates": [
"{{if eq \"Charging\" .State.String}}#40c4ff{{end}}",
"{{if eq \"Discharging\" .State.String}}#ff5722{{end}}",
"{{if eq \"Full\" .State.String}}#4caf50{{end}}"
],
"foreground": "#f36943",
"properties": {
"charged_icon": "\uf583 ",
"charging_icon": "\uf588 ",
"discharging_icon": "\uf57d "
},
"style": "plain",
"template": " {{ if not .Error }}{{ .Icon }}{{ .Percentage }}{{ end }}{{ .Error }}% ",
"type": "battery"
},
{
"type": "owm",
"style": "plain",
"foreground": "#91ddff",
"template": "{{.Weather}} {{ .Temperature }}{{.UnitIcon }} ",
"properties": {
"apikey": "3d07cc3aeda66d90243a06c9f4deac5f",
"location": "BRISTOL,GB",
"units": "metric",
"http_timeout": 100,
"cache_timeout": 10
}
},
{
"foreground": "#ffffff",
"properties": {
"time_format": "_2 Jan"
},
"style": "plain",
"template": " {{ .CurrentDate | date .Format }}",
"type": "time"
},
{
"foreground": "#91ddff",
"properties": {
"datetime_format": "2022-01-02 15:04:05",
"time_format": "15:04:05"
},
"style": "plain",
"template": " {{ .CurrentDate | date .Format }}",
"type": "time"
}
],
"type": "prompt"
},
{
"type": "newline"
},
{
"alignment": "left",
"segments": [{
"Enabled": false,
"background": "#ff8800",
"foreground": "#100e23",
"powerline_symbol": "\ue0c0",
"properties": {
"root_icon": ""
},
"style": "powerline",
"template": " \uf0e7 ",
"type": "root"
},
{
"Enabled": false,
"background": "#8800dd",
"foreground": "#ffffff",
"powerline_symbol": "\ue0b0",
"properties": {
"style": "amarillo",
"threshold": 500
},
"style": "powerline",
"template": " {{ .FormattedMs }} ",
"type": "executiontime"
},
{
"background": "#ffffff",
"foreground": "#100e23",
"powerline_symbol": "\ue0b0",
"style": "powerline",
"template": " {{ .Name }} ",
"type": "shell"
},
{
"Enabled": false,
"background": "#91ddff",
"foreground": "#100e23",
"powerline_symbol": "\ue0b0",
"properties": {
"folder_icon": "\uf115",
"folder_separator_icon": " \ue0b1 ",
"style": "full"
},
"style": "powerline",
"template": " {{ .Path }} ",
"type": "path"
},
{
"background": "#95ffa4",
"background_templates": [
"{{ if or (.Working.Changed) (.Staging.Changed) }}#FF9248{{ end }}",
"{{ if and (gt .Ahead 0) (gt .Behind 0) }}#ff4500{{ end }}",
"{{ if gt .Ahead 0 }}#B388FF{{ end }}",
"{{ if gt .Behind 0 }}#B388FF{{ end }}"
],
"foreground": "#193549",
"leading_diamond": "\ue0b6",
"powerline_symbol": "\ue0b0",
"properties": {
"branch_max_length": 25,
"fetch_stash_count": true,
"fetch_status": true,
"fetch_upstream_icon": true
},
"style": "powerline",
"template": " {{ .UpstreamIcon }}{{ .HEAD }}{{if .BranchStatus }} {{ .BranchStatus }}{{ end }}{{ if .Working.Changed }} \uf044 {{ .Working.String }}{{ end }}{{ if and (.Working.Changed) (.Staging.Changed) }} |{{ end }}{{ if .Staging.Changed }} \uf046 {{ .Staging.String }}{{ end }}{{ if gt .StashCount 0 }} \uf692 {{ .StashCount }}{{ end }} ",
"trailing_diamond": "\ue0b4",
"type": "git"
},
{
"Enabled": false,
"background": "#906cff",
"foreground": "#100e23",
"powerline_symbol": "\ue0b0",
"style": "powerline",
"template": " \ue235 {{ if .Error }}{{ .Error }}{{ else }}{{ if .Venv }}{{ .Venv }} {{ end }}{{ .Full }}{{ end }} ",
"type": "python"
},
{
"Enabled": false,
"background": "#ff8080",
"foreground": "#ffffff",
"powerline_symbol": "\ue0b0",
"style": "powerline",
"template": " {{ if gt .Code 0 }}\uf00d {{ .Meaning }}{{ else }}\uf42e{{ end }} ",
"type": "exit"
}
],
"type": "prompt"
},
{
"type": "newline"
},
{
"alignment": "left",
"segments": [{
"Enabled": false,
"foreground": "#007ACC",
"style": "plain",
"template": "\u276f ",
"type": "text"
}],
"type": "prompt"
}
],
"transient_prompt": {
"background": "transparent",
"foreground": "#666666",
"template": "[{{ .Segments.Time.CurrentDate | date \"2006-01-02 15:04:05\" }}]{{ if .Segments.Executiontime.Ms }}{{ if eq \"False\" (title (default \"False\" .Env.DISABLE_SEGMENT_TRANSIENT_EXEC_TIME)) }}[{{ .Segments.Executiontime.FormattedMs }}]{{ end }}{{ end }}\u276f "
},
"version": 2
}
What OS are you seeing the problem on?
Windows
Which shell are you using?
powershell
Log output
[2022-10-08 13:03:51]❯ oh-my-posh debugAn exception occurred in custom key handler, see $error for more information: Object reference not set to an instance of an object.
### ran the same with v1
Version: 12.0.1
Segments:
ConsoleTitle(false) - 0 ms -
root(false) - 0 ms -
executiontime(false) - 0 ms -
spotify(false) - 1 ms -
session(true) - 1 ms - David
path(true) - 0 ms - D:\Code\Personal
git(false) - 4 ms -
python(false) - 0 ms -
exit(false) - 0 ms -
owm(false) - 59 ms -
time(true) - 0 ms - 13:06:49
text(true) - 0 ms - ❯
Run duration: 84.9002ms
Cache path: C:\Users\David\AppData\Local\oh-my-posh
Config path: C:\Users\David\Documents\WindowsPowerShell\Scripts\ParagnosterPlus.omp.json
Logs:
2022/10/08 13:06:49 debug: Getenv
C:\Users\David\AppData\Local
2022/10/08 13:06:49 Getenv duration: 0s, args: LOCALAPPDATA
2022/10/08 13:06:49 CachePath duration: 0s, args:
2022/10/08 13:06:49 debug: Getenv
C:\Users\David\Documents\WindowsPowerShell\Scripts\ParagnosterPlus.omp.json
2022/10/08 13:06:49 Getenv duration: 0s, args: POSH_THEME
2022/10/08 13:06:49 debug: Shell
process name: powershell.exe
2022/10/08 13:06:49 Shell duration: 15.8655ms, args:
2022/10/08 13:06:49 resolveConfigPath duration: 15.8655ms, args:
2022/10/08 13:06:49 Init duration: 15.8655ms, args:
2022/10/08 13:06:49 Flags duration: 0s, args:
2022/10/08 13:06:49 config.loadConfig duration: 510.3µs, args:
2022/10/08 13:06:49 Flags duration: 0s, args:
2022/10/08 13:06:49 debug: Getenv
2022/10/08 13:06:49 Getenv duration: 0s, args: OMP_CACHE_DISABLED
2022/10/08 13:06:49 WindowsRegistryKeyValue duration: 0s, args: HKEY_CURRENT_USER\Software\Microsoft\Windows\DWM\ColorizationColor
2022/10/08 13:06:49 GOOS duration: 0s, args:
2022/10/08 13:06:49 GOOS duration: 0s, args:
2022/10/08 13:06:49 GOOS duration: 0s, args:
2022/10/08 13:06:49 GOOS duration: 0s, args:
2022/10/08 13:06:49 GOOS duration: 0s, args:
2022/10/08 13:06:49 GOOS duration: 0s, args:
2022/10/08 13:06:49 GOOS duration: 0s, args:
2022/10/08 13:06:49 GOOS duration: 0s, args:
2022/10/08 13:06:49 GOOS duration: 0s, args:
2022/10/08 13:06:49 GOOS duration: 0s, args:
2022/10/08 13:06:49 GOOS duration: 0s, args:
2022/10/08 13:06:49 GOOS duration: 0s, args:
2022/10/08 13:06:49 GOOS duration: 0s, args:
2022/10/08 13:06:49 GOOS duration: 0s, args:
2022/10/08 13:06:49 GOOS duration: 0s, args:
2022/10/08 13:06:49 GOOS duration: 0s, args:
2022/10/08 13:06:49 GOOS duration: 0s, args:
2022/10/08 13:06:49 GOOS duration: 0s, args:
2022/10/08 13:06:49 GOOS duration: 0s, args:
2022/10/08 13:06:49 debug: WindowsRegistryKeyValue
ColorizationColor(DWORD): 0xC40078D4
2022/10/08 13:06:49 Root duration: 0s, args:
2022/10/08 13:06:49 Shell duration: 0s, args:
2022/10/08 13:06:49 ErrorCode duration: 0s, args:
2022/10/08 13:06:49 IsWsl duration: 0s, args:
2022/10/08 13:06:49 GOOS duration: 0s, args:
2022/10/08 13:06:49 debug: Pwd
D:\Code\Personal
2022/10/08 13:06:49 Pwd duration: 0s, args:
2022/10/08 13:06:49 debug: Home
C:\Users\David
2022/10/08 13:06:49 GOOS duration: 0s, args:
2022/10/08 13:06:49 GOOS duration: 0s, args:
2022/10/08 13:06:49 GOOS duration: 0s, args:
2022/10/08 13:06:49 GOOS duration: 0s, args:
2022/10/08 13:06:49 GOOS duration: 0s, args:
2022/10/08 13:06:49 GOOS duration: 0s, args:
2022/10/08 13:06:49 GOOS duration: 0s, args:
2022/10/08 13:06:49 GOOS duration: 0s, args:
2022/10/08 13:06:49 GOOS duration: 0s, args:
2022/10/08 13:06:49 GOOS duration: 0s, args:
2022/10/08 13:06:49 GOOS duration: 0s, args:
2022/10/08 13:06:49 debug: User
David
2022/10/08 13:06:49 User duration: 0s, args:
2022/10/08 13:06:49 debug: Host
COMPLEX
2022/10/08 13:06:49 Host duration: 0s, args:
2022/10/08 13:06:49 GOOS duration: 0s, args:
2022/10/08 13:06:49 TemplateCache duration: 0s, args:
2022/10/08 13:06:49 Flags duration: 0s, args:
2022/10/08 13:06:49 debug: Pwd
D:\Code\Personal
2022/10/08 13:06:49 Pwd duration: 0s, args:
2022/10/08 13:06:49 debug: Home
C:\Users\David
2022/10/08 13:06:49 GOOS duration: 0s, args:
2022/10/08 13:06:49 Root duration: 0s, args:
2022/10/08 13:06:49 debug: Pwd
D:\Code\Personal
2022/10/08 13:06:49 Pwd duration: 0s, args:
2022/10/08 13:06:49 debug: Home
C:\Users\David
2022/10/08 13:06:49 GOOS duration: 0s, args:
2022/10/08 13:06:49 ExecutionTime duration: 0s, args:
2022/10/08 13:06:49 debug: Pwd
D:\Code\Personal
2022/10/08 13:06:49 Pwd duration: 0s, args:
2022/10/08 13:06:49 debug: Home
C:\Users\David
2022/10/08 13:06:49 GOOS duration: 0s, args:
2022/10/08 13:06:49 WindowTitle duration: 1.0209ms, args: ^(Spotify.*)|(.*\s-\s.*)$
2022/10/08 13:06:49 debug: Pwd
D:\Code\Personal
2022/10/08 13:06:49 Pwd duration: 0s, args:
2022/10/08 13:06:49 debug: Home
C:\Users\David
2022/10/08 13:06:49 GOOS duration: 0s, args:
2022/10/08 13:06:49 debug: Getenv
2022/10/08 13:06:49 Getenv duration: 0s, args: SSH_CONNECTION
2022/10/08 13:06:49 debug: Getenv
2022/10/08 13:06:49 Getenv duration: 0s, args: SSH_CLIENT
2022/10/08 13:06:49 TemplateCache duration: 0s, args:
2022/10/08 13:06:49 TemplateCache duration: 0s, args:
2022/10/08 13:06:49 Shell duration: 0s, args:
2022/10/08 13:06:49 debug: Pwd
D:\Code\Personal
2022/10/08 13:06:49 Pwd duration: 0s, args:
2022/10/08 13:06:49 debug: Home
C:\Users\David
2022/10/08 13:06:49 GOOS duration: 0s, args:
2022/10/08 13:06:49 Shell duration: 0s, args:
2022/10/08 13:06:49 Shell duration: 0s, args:
2022/10/08 13:06:49 Flags duration: 0s, args:
2022/10/08 13:06:49 debug: Pwd
D:\Code\Personal
2022/10/08 13:06:49 Pwd duration: 0s, args:
2022/10/08 13:06:49 debug: Home
C:\Users\David
2022/10/08 13:06:49 GOOS duration: 0s, args:
2022/10/08 13:06:49 PathSeparator duration: 0s, args:
2022/10/08 13:06:49 GOOS duration: 0s, args:
2022/10/08 13:06:49 GOOS duration: 0s, args:
2022/10/08 13:06:49 GOOS duration: 0s, args:
2022/10/08 13:06:49 PathSeparator duration: 0s, args:
2022/10/08 13:06:49 GOOS duration: 0s, args:
2022/10/08 13:06:49 PathSeparator duration: 0s, args:
2022/10/08 13:06:49 GOOS duration: 0s, args:
2022/10/08 13:06:49 PathSeparator duration: 0s, args:
2022/10/08 13:06:49 GOOS duration: 0s, args:
2022/10/08 13:06:49 PathSeparator duration: 0s, args:
2022/10/08 13:06:49 GOOS duration: 0s, args:
2022/10/08 13:06:49 PathSeparator duration: 0s, args:
2022/10/08 13:06:49 PathSeparator duration: 0s, args:
2022/10/08 13:06:49 PathSeparator duration: 0s, args:
2022/10/08 13:06:49 PathSeparator duration: 0s, args:
2022/10/08 13:06:49 IsWsl duration: 0s, args:
2022/10/08 13:06:49 StackCount duration: 0s, args:
2022/10/08 13:06:49 DirIsWritable duration: 0s, args:
2022/10/08 13:06:49 TemplateCache duration: 0s, args:
2022/10/08 13:06:49 TemplateCache duration: 0s, args:
2022/10/08 13:06:49 Shell duration: 0s, args:
2022/10/08 13:06:49 debug: Pwd
D:\Code\Personal
2022/10/08 13:06:49 Pwd duration: 0s, args:
2022/10/08 13:06:49 debug: Home
C:\Users\David
2022/10/08 13:06:49 GOOS duration: 0s, args:
2022/10/08 13:06:49 GOOS duration: 0s, args:
2022/10/08 13:06:49 debug: CommandPath
C:\Program Files\Git\cmd\git.exe
2022/10/08 13:06:49 CommandPath duration: 4.401ms, args: git.exe
2022/10/08 13:06:49 HasCommand duration: 4.401ms, args: git.exe
2022/10/08 13:06:49 debug: Pwd
D:\Code\Personal
2022/10/08 13:06:49 Pwd duration: 0s, args:
2022/10/08 13:06:49 error: HasParentFilePath
CreateFile D:\.git: The system cannot find the file specified.
2022/10/08 13:06:49 HasParentFilePath duration: 0s, args: .git
2022/10/08 13:06:49 debug: Pwd
D:\Code\Personal
2022/10/08 13:06:49 Pwd duration: 0s, args:
2022/10/08 13:06:49 debug: Home
C:\Users\David
2022/10/08 13:06:49 GOOS duration: 0s, args:
2022/10/08 13:06:49 debug: Pwd
D:\Code\Personal
2022/10/08 13:06:49 Pwd duration: 0s, args:
2022/10/08 13:06:49 debug: Home
C:\Users\David
2022/10/08 13:06:49 debug: Getenv
2022/10/08 13:06:49 Getenv duration: 0s, args: VIRTUAL_ENV
2022/10/08 13:06:49 debug: Getenv
2022/10/08 13:06:49 Getenv duration: 0s, args: CONDA_ENV_PATH
2022/10/08 13:06:49 debug: Getenv
2022/10/08 13:06:49 Getenv duration: 0s, args: CONDA_DEFAULT_ENV
2022/10/08 13:06:49 debug: Pwd
D:\Code\Personal
2022/10/08 13:06:49 Pwd duration: 0s, args:
2022/10/08 13:06:49 debug: Home
C:\Users\David
2022/10/08 13:06:49 GOOS duration: 0s, args:
2022/10/08 13:06:49 ErrorCode duration: 0s, args:
2022/10/08 13:06:49 ErrorCode duration: 0s, args:
2022/10/08 13:06:49 Flags duration: 0s, args:
2022/10/08 13:06:49 debug: Pwd
D:\Code\Personal
2022/10/08 13:06:49 Pwd duration: 0s, args:
2022/10/08 13:06:49 debug: Home
C:\Users\David
2022/10/08 13:06:49 GOOS duration: 0s, args:
2022/10/08 13:06:49 debug: HTTPRequest
GET /data/2.5/weather?q=BRISTOL,UK&units=metric&appid=3d07cc3aeda66d90243a06c9f4deac5f HTTP/1.1
Host: api.openweathermap.org
User-Agent: Go-http-client/1.1
Accept-Encoding: gzip
2022/10/08 13:06:49 error: HTTPRequest
Get "http://api.openweathermap.org/data/2.5/weather?q=BRISTOL,UK&units=metric&appid=3d07cc3aeda66d90243a06c9f4deac5f": context deadline exceeded
2022/10/08 13:06:49 HTTPRequest duration: 59.6691ms, args: http://api.openweathermap.org/data/2.5/weather?q=BRISTOL,UK&units=metric&appid=3d07cc3aeda66d90243a06c9f4deac5f
2022/10/08 13:06:49 debug: Pwd
D:\Code\Personal
2022/10/08 13:06:49 Pwd duration: 0s, args:
2022/10/08 13:06:49 debug: Home
C:\Users\David
2022/10/08 13:06:49 GOOS duration: 0s, args:
2022/10/08 13:06:49 TemplateCache duration: 0s, args:
2022/10/08 13:06:49 TemplateCache duration: 0s, args:
2022/10/08 13:06:49 Shell duration: 0s, args:
2022/10/08 13:06:49 Flags duration: 0s, args:
2022/10/08 13:06:49 Flags duration: 0s, args:
2022/10/08 13:06:49 debug: Pwd
D:\Code\Personal
2022/10/08 13:06:49 Pwd duration: 0s, args:
2022/10/08 13:06:49 debug: Home
C:\Users\David
2022/10/08 13:06:49 GOOS duration: 0s, args:
2022/10/08 13:06:49 TemplateCache duration: 0s, args:
2022/10/08 13:06:49 TemplateCache duration: 0s, args:
2022/10/08 13:06:49 Shell duration: 0s, args:
2022/10/08 13:06:49 debug: Getenv
C:\Users\David\AppData\Local
2022/10/08 13:06:49 Getenv duration: 0s, args: LOCALAPPDATA
2022/10/08 13:06:49 CachePath duration: 58.6µs, args:
2022/10/08 13:06:49 Flags duration: 0s, args:
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 17 (6 by maintainers)
@JanDeDobbeleer we’ve managed to confirm this is only affecting PowerShell 5.1. I looped our PSReadLine maintainer in, maybe we’ll figure it out, though 5.1 is in maintenance mode and for the extension is supported on a best effort basis 🤷 PowerShell 7 and oh-my-posh work just great 👍
@andschwa I understand. No future in 5.1 anyways.