JanDeDobbeleer / oh-my-posh

The most customisable and low-latency cross platform/shell prompt renderer
https://ohmyposh.dev
MIT License
16.79k stars 2.35k forks source link

Recent updates failing at times with below stacktrace, Get-PoshThemes also failing for some themes #2058

Closed vamshikrishna83 closed 2 years ago

vamshikrishna83 commented 2 years ago

Code of Conduct

What happened?

Get-PoshThemes to display all themes supported by OhMyPosh. With recent versions, for some themes, this is resulting in below stacktrace. Multiple themes are resulting in similar looking failure, which makes me think the issue is not related to themes.

Theme: stelbent.minimal

                                                                                                                                                                                                                              pwsh | 17:10:25
┌ vamshikb@VAMSHIKB-IN  " --shell pwsh 
└ $

Theme: takuya

oh-my-posh fatal error rendering root segment:runtime error: invalid memory address or nil pointer dereference

goroutine 19 [running]:
runtime/debug.Stack()
        /opt/hostedtoolcache/go/1.18.0/x64/src/runtime/debug/stack.go:24 +0x65
oh-my-posh/engine.(*Segment).renderText.func1()
        /home/runner/work/oh-my-posh/oh-my-posh/src/engine/segment.go:326 +0x58
panic({0xea0bc0, 0x1956900})
        /opt/hostedtoolcache/go/1.18.0/x64/src/runtime/panic.go:838 +0x207
strings.Count({0x0?, 0xf?}, {0xf3a608?, 0xf?})
        /opt/hostedtoolcache/go/1.18.0/x64/src/strings/strings.go:47 +0x50
strings.Replace({0x0, 0x10}, {0xf3a608, 0x1}, {0xf3a5f2, 0x1}, 0xffffffffffffffff)
        /opt/hostedtoolcache/go/1.18.0/x64/src/strings/strings.go:1003 +0xcf
strings.ReplaceAll(...)
        /opt/hostedtoolcache/go/1.18.0/x64/src/strings/strings.go:1037
oh-my-posh/environment.dirMatchesOneOf({0x0?, 0x0?}, {0xc00038a048, 0x11}, {0xf3d6ad, 0x7}, {0x19c3d40, 0x0, 0xc00021c070?})
        /home/runner/work/oh-my-posh/oh-my-posh/src/environment/shell.go:737 +0x72
oh-my-posh/environment.(*ShellEnvironment).DirMatchesOneOf(0xc00021c070, {0x0, 0x10}, {0x19c3d40, 0x0, 0x0})
        /home/runner/work/oh-my-posh/oh-my-posh/src/environment/shell.go:733 +0x125
oh-my-posh/engine.(*Segment).cwdExcluded(0xc0000e8140)
        /home/runner/work/oh-my-posh/oh-my-posh/src/engine/segment.go:209 +0xe2
oh-my-posh/engine.(*Segment).shouldIncludeFolder(0xc0000e8140)
        /home/runner/work/oh-my-posh/oh-my-posh/src/engine/segment.go:182 +0x36
oh-my-posh/engine.(*Segment).renderText(0xc0000e8140, {0x1070350?, 0xc00021c070?})
        /home/runner/work/oh-my-posh/oh-my-posh/src/engine/segment.go:332 +0x7b
oh-my-posh/engine.(*Block).renderSegmentsText.func1(0x0?)
        /home/runner/work/oh-my-posh/oh-my-posh/src/engine/block.go:88 +0x65
created by oh-my-posh/engine.(*Block).renderSegmentsText
        /home/runner/work/oh-my-posh/oh-my-posh/src/engine/block.go:86 +0x98

╭─ pwsh error D:" --shell pwsh                                                                                                                                                                                                17:10:25 
╰─❯

Theme: the-unnamed

" --shell pwsh
❯

Theme

{
  "$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
  "blocks": [
    {
      "alignment": "left",
      "segments": [
        {
          "background": "#0000ff",
          "foreground": "#ffffff",
          "powerline_symbol": "\ue0b0",
          "properties": {
            "style": "full"
          },
          "style": "powerline",
          "template": " {{ .Path }} ",
          "type": "path"
        },
        {
          "background": "#00ff00",
          "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": "#000000",
          "leading_diamond": "\ue0b6",
          "powerline_symbol": "\ue0b0",
          "properties": {
            "branch_max_length": 50,
            "fetch_stash_count": true,
            "fetch_status": true,
            "fetch_upstream_icon": true
          },
          "style": "powerline",
          "template": " {{ .HEAD }} {{ .BranchStatus }}{{ if .Working.Changed }} \uf044 {{ .Working.String }}{{ end }}{{ if and (.Staging.Changed) (.Working.Changed) }} |{{ end }}{{ if .Staging.Changed }} \uf046 {{ .Staging.String }}{{ end }}{{ if gt .StashCount 0}} \uf692 {{ .StashCount }}{{ end }}{{ if gt .WorktreeCount 0}} \uf1bb {{ .WorktreeCount }}{{ end }} ",
          "trailing_diamond": "\ue0b4",
          "type": "git"
        }
      ],
      "type": "prompt"
    }
  ],
  "final_space": true,
  "version": 2
}

What OS are you seeing the problem on?

Windows

Which shell are you using?

powershell

Log output

Version: 7.59.4

Segments:

ConsoleTitle(false) -   0 ms - 
path(true)  -   0 ms -  D:\
git(false)  -  40 ms -

Run duration: 40.5879ms

Cache path: C:\Users\vamshikb\AppData\Local\oh-my-posh

Logs:

2022/04/07 17:13:12 Flags duration: 0s, args:
2022/04/07 17:13:12 Flags duration: 0s, args:
2022/04/07 17:13:12 debug: Getenv

2022/04/07 17:13:12 Getenv duration: 0s, args: OMP_CACHE_DISABLED
2022/04/07 17:13:12 Root duration: 0s, args:
2022/04/07 17:13:12 Shell duration: 0s, args:
2022/04/07 17:13:12 ErrorCode duration: 0s, args:
2022/04/07 17:13:12 IsWsl duration: 0s, args:
2022/04/07 17:13:12 debug: Pwd
D:\
2022/04/07 17:13:12 Pwd duration: 0s, args:
2022/04/07 17:13:12 debug: Home
C:\Users\vamshikb
2022/04/07 17:13:12 PathSeparator duration: 0s, args:
2022/04/07 17:13:12 PathSeparator duration: 0s, args:
2022/04/07 17:13:12 debug: User
vamshikb
2022/04/07 17:13:12 User duration: 0s, args:
2022/04/07 17:13:12 debug: Host
VAMSHIKB-IN
2022/04/07 17:13:12 Host duration: 503.2µs, args:
2022/04/07 17:13:12 GOOS duration: 0s, args:
2022/04/07 17:13:12 TemplateCache duration: 503.2µs, args:
2022/04/07 17:13:12 debug: Pwd
D:\
2022/04/07 17:13:12 Pwd duration: 0s, args:
2022/04/07 17:13:12 debug: Home
C:\Users\vamshikb
2022/04/07 17:13:12 GOOS duration: 0s, args:
2022/04/07 17:13:12 debug: Pwd
D:\
2022/04/07 17:13:12 Pwd duration: 0s, args:
2022/04/07 17:13:12 Flags duration: 0s, args:
2022/04/07 17:13:12 debug: Pwd
D:\
2022/04/07 17:13:12 Pwd duration: 0s, args:
2022/04/07 17:13:12 debug: Home
C:\Users\vamshikb
2022/04/07 17:13:12 GOOS duration: 0s, args:
2022/04/07 17:13:12 GOOS duration: 0s, args:
2022/04/07 17:13:12 PathSeparator duration: 0s, args:
2022/04/07 17:13:12 GOOS duration: 0s, args:
2022/04/07 17:13:12 IsWsl duration: 0s, args:
2022/04/07 17:13:12 StackCount duration: 0s, args:
2022/04/07 17:13:12 TemplateCache duration: 0s, args:
2022/04/07 17:13:12 debug: Pwd
D:\
2022/04/07 17:13:12 Pwd duration: 0s, args:
2022/04/07 17:13:12 debug: Home
C:\Users\vamshikb
2022/04/07 17:13:12 GOOS duration: 0s, args:
2022/04/07 17:13:12 GOOS duration: 0s, args:
2022/04/07 17:13:12 HasCommand duration: 39.5253ms, args: git.exe
2022/04/07 17:13:12 debug: Pwd
D:\
2022/04/07 17:13:12 Pwd duration: 0s, args:
2022/04/07 17:13:12 error: HasParentFilePath
CreateFile D:\.git: The system cannot find the file specified.
2022/04/07 17:13:12 HasParentFilePath duration: 559.4µs, args: .git
2022/04/07 17:13:12 debug: Getenv
C:\Users\vamshikb\AppData\Local
2022/04/07 17:13:12 Getenv duration: 0s, args: LOCALAPPDATA
2022/04/07 17:13:12 CachePath duration: 0s, args:
JanDeDobbeleer commented 2 years ago

@bvkrish83 duplicate of #2038 and a mitigation is in place as of 7.59.5 (so updating will resolve that for now)

MovGP0 commented 2 years ago

I still experience this error with oh-my-posh version 7.70.0 using the default theme:

oh-my-posh fatal error rendering path segment:runtime error: invalid memory address or nil pointer dereference

goroutine 19 [running]:
runtime/debug.Stack()
        /opt/hostedtoolcache/go/1.18.0/x64/src/runtime/debug/stack.go:24 +0x65
oh-my-posh/engine.(*Segment).renderText.func1()
        /home/runner/work/oh-my-posh/oh-my-posh/src/engine/segment.go:326 +0x58
panic({0xb90b40, 0x1646900})
        /opt/hostedtoolcache/go/1.18.0/x64/src/runtime/panic.go:838 +0x207
strings.Count({0x0?, 0xc00006c8a0?}, {0xc2a548?, 0xc000205200?})
        /opt/hostedtoolcache/go/1.18.0/x64/src/strings/strings.go:47 +0x50
strings.Replace({0x0, 0x18}, {0xc2a548, 0x1}, {0xc2a532, 0x1}, 0xffffffffffffffff)
        /opt/hostedtoolcache/go/1.18.0/x64/src/strings/strings.go:1003 +0xcf
strings.ReplaceAll(...)
        /opt/hostedtoolcache/go/1.18.0/x64/src/strings/strings.go:1037
oh-my-posh/environment.DirMatchesOneOf({0xd601f0, 0xc0002260e0}, {0x0?, 0xe?}, {0x16b3d40, 0x0, 0x0?})
        /home/runner/work/oh-my-posh/oh-my-posh/src/environment/shell.go:724 +0x76
oh-my-posh/engine.(*Segment).cwdExcluded(0xc0000fc140)
        /home/runner/work/oh-my-posh/oh-my-posh/src/engine/segment.go:209 +0xde
oh-my-posh/engine.(*Segment).shouldIncludeFolder(0xc0000fc140)
        /home/runner/work/oh-my-posh/oh-my-posh/src/engine/segment.go:182 +0x36
oh-my-posh/engine.(*Segment).renderText(0xc0000fc140, {0xd601f0?, 0xc0002260e0?})
        /home/runner/work/oh-my-posh/oh-my-posh/src/engine/segment.go:332 +0x7b
oh-my-posh/engine.(*Block).renderSegmentsText.func1(0x0?)
        /home/runner/work/oh-my-posh/oh-my-posh/src/engine/block.go:88 +0x65
created by oh-my-posh/engine.(*Block).renderSegmentsText
        /home/runner/work/oh-my-posh/oh-my-posh/src/engine/block.go:86 +0x98
JanDeDobbeleer commented 2 years ago

@MovGP0 this time, it's a different issue though. There's one element we still need to synchronize it seems. BTW, which platform is this (I'm assuming Windows as that's the only place where I can see this fail)?

MovGP0 commented 2 years ago

@MovGP0 this time, it's a different issue though. There's one element we still need to synchronize it seems. BTW, which platform is this (I'm assuming Windows as that's the only place where I can see this fail)?

Windows 11 (v10.0.22598 / Kernel 6.3) / PowerShell 7.2.2

JanDeDobbeleer commented 2 years ago

@MovGP0 I pushed an update, can you see if that fixes the issue for you?

MovGP0 commented 2 years ago

@MovGP0 I pushed an update, can you see if that fixes the issue for you?

Just had the problem again:

oh-my-posh fatal error rendering path segment:runtime error: invalid memory address or nil pointer dereference

goroutine 19 [running]:
runtime/debug.Stack()
        /opt/hostedtoolcache/go/1.18.0/x64/src/runtime/debug/stack.go:24 +0x65
oh-my-posh/engine.(*Segment).renderText.func1()
        /home/runner/work/oh-my-posh/oh-my-posh/src/engine/segment.go:326 +0x58
panic({0xb90b40, 0x1646900})
        /opt/hostedtoolcache/go/1.18.0/x64/src/runtime/panic.go:838 +0x207
strings.Count({0x0?, 0xc0000667e0?}, {0xc2a548?, 0xc000200f60?})
        /opt/hostedtoolcache/go/1.18.0/x64/src/strings/strings.go:47 +0x50
strings.Replace({0x0, 0x2}, {0xc2a548, 0x1}, {0xc2a532, 0x1}, 0xffffffffffffffff)
        /opt/hostedtoolcache/go/1.18.0/x64/src/strings/strings.go:1003 +0xcf
strings.ReplaceAll(...)
        /opt/hostedtoolcache/go/1.18.0/x64/src/strings/strings.go:1037
oh-my-posh/environment.DirMatchesOneOf({0xd601f0, 0xc0000be000}, {0x0?, 0xe?}, {0x16b3d40, 0x0, 0x0?})
        /home/runner/work/oh-my-posh/oh-my-posh/src/environment/shell.go:724 +0x76
oh-my-posh/engine.(*Segment).cwdExcluded(0xc000292140)
        /home/runner/work/oh-my-posh/oh-my-posh/src/engine/segment.go:209 +0xde
oh-my-posh/engine.(*Segment).shouldIncludeFolder(0xc000292140)
        /home/runner/work/oh-my-posh/oh-my-posh/src/engine/segment.go:182 +0x36
oh-my-posh/engine.(*Segment).renderText(0xc000292140, {0xd601f0?, 0xc0000be000?})
        /home/runner/work/oh-my-posh/oh-my-posh/src/engine/segment.go:332 +0x7b
oh-my-posh/engine.(*Block).renderSegmentsText.func1(0x0?)
        /home/runner/work/oh-my-posh/oh-my-posh/src/engine/block.go:88 +0x65
created by oh-my-posh/engine.(*Block).renderSegmentsText
        /home/runner/work/oh-my-posh/oh-my-posh/src/engine/block.go:86 +0x98

Unfortunately, this error only occurs occationally and is not always reproduceable.

github-actions[bot] commented 7 months ago

This issue has been automatically locked since there has not been any recent activity (i.e. last half year) after it was closed. It helps our maintainers focus on the active issues. If you have found a problem that seems similar, please open a discussion first, complete the body with all the details necessary to reproduce, and mention this issue as reference.