JanDeDobbeleer / oh-my-posh

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

"invalid memory address or nil pointer dereference" in various prompt modules #1182

Closed theconnstruct closed 2 years ago

theconnstruct commented 3 years ago

Code of Conduct

What happened?

At random times, rendering one or more elements of the prompt results in errors of the following format:

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

The affected segment displays the text "error" when this event occurs. The affected segment can be something as trivial as the operating system logo or the last execution timer.

Version

> Get-Module oh-my-posh | select Version

Version
-------
5.19.0

Theme

night-owl, no modifications.

What OS are you seeing the problem on?

Windows

Which shell are you using?

powershell

Relevant log output

╭─       0ms                                                                                                              21:45:38 
╰─
oh-my-posh fatal error rendering executiontime segment:runtime error: invalid memory address or nil pointer dereference
╭─       error                                                                                                            21:45:39 
╰─
╭─       0ms                                                                                                              21:45:40 
╰─
╭─       0ms                                                                                                              21:45:41 
╰─
╭─       0ms                                                                                                              21:45:42 
╰─
╭─       0ms                                                                                                              21:45:43 
╰─
╭─       0ms                                                                                                              21:45:44 
╰─
╭─       0ms                                                                                                              21:45:45 
╰─
╭─       0ms                                                                                                              21:45:46 
╰─
╭─       0ms                                                                                                              21:45:47 
╰─
╭─       0ms                                                                                                              21:45:48 
╰─
╭─       0ms                                                                                                              21:45:49 
╰─
╭─       0ms                                                                                                              21:45:50 
╰─
╭─       0ms                                                                                                              21:45:51 
╰─
╭─       0ms                                                                                                              21:45:52 
╰─
╭─       0ms                                                                                                              21:45:53 
╰─
oh-my-posh fatal error rendering os segment:runtime error: invalid memory address or nil pointer dereference
╭─ error      0ms                                                                                                          21:45:54 
╰─
theconnstruct commented 3 years ago

Of note, I also use the same theme inside several WSL instances and on a few Linux servers. In Windows/Powershell is the only time I see this behavior.

lnu commented 3 years ago

I also noticed this a few days ago. Happened to me on windows, never on MacOS.

JanDeDobbeleer commented 3 years ago

Might be related to updating some dependencies, will check (nil pointers are identifiable luckily).

JanDeDobbeleer commented 2 years ago

@lnu @cyveris looking at that I have no idea what's causing this, it's a good idea anyways to add the stack trace to the error so we have a clue of what's going on when it happens again.

amaechler commented 2 years ago

Just noticed this for the first time, with the following stack trace:

❯ cd Pli

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

goroutine 8 [running]:
runtime/debug.Stack()
        /opt/hostedtoolcache/go/1.17.3/x64/src/runtime/debug/stack.go:24 +0x65
main.(*Segment).setStringValue.func1()
        /home/runner/work/oh-my-posh/oh-my-posh/src/segment.go:287 +0x58
panic({0xd43cc0, 0x17100b0})
        /opt/hostedtoolcache/go/1.17.3/x64/src/runtime/panic.go:1038 +0x215
main.(*GitStatus).Changed(...)
        /home/runner/work/oh-my-posh/oh-my-posh/src/segment_git.go:35
main.(*git).deprecatedString(0xc00030a000, 0xfa)
        /home/runner/work/oh-my-posh/oh-my-posh/src/segment_deprecated.go:92 +0x131
main.(*git).string(0xc00030a000)
        /home/runner/work/oh-my-posh/oh-my-posh/src/segment_git.go:206 +0x2b1
main.(*Segment).string(...)
        /home/runner/work/oh-my-posh/oh-my-posh/src/segment.go:141
main.(*Segment).setStringValue(0xc0001cc900, {0xea8500, 0xc00006eb90})
        /home/runner/work/oh-my-posh/oh-my-posh/src/segment.go:297 +0xc5
main.(*Block).setStringValues.func1(0x0)
        /home/runner/work/oh-my-posh/oh-my-posh/src/block.go:87 +0x65
created by main.(*Block).setStringValues
        /home/runner/work/oh-my-posh/oh-my-posh/src/block.go:85 +0x9d

 ~\Development\Pandell\Pli  error 
❯
lnu commented 2 years ago

it's an issue with the latest changes. @JanDeDobbeleer has been notified. https://github.com/JanDeDobbeleer/oh-my-posh/commit/04f841d1b323f58e8e1b7c33f96eae26ea00558b.

For the time being rollback to a previous version, the fix is on its way.

VHamar commented 2 years ago

Getting the same when running Get-PoshThemes in WindowsTerminal on Win11

Theme: atomic

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

goroutine 9 [running]: runtime/debug.Stack() /opt/hostedtoolcache/go/1.17.3/x64/src/runtime/debug/stack.go:24 +0x65 main.(Segment).setStringValue.func1() /home/runner/work/oh-my-posh/oh-my-posh/src/segment.go:287 +0x58 panic({0xb73cc0, 0x15400b0}) /opt/hostedtoolcache/go/1.17.3/x64/src/runtime/panic.go:1038 +0x215 main.(GitStatus).add(...) /home/runner/work/oh-my-posh/oh-my-posh/src/segment_git.go:30 main.(git).setGitStatus.func1({0xc000330239, 0x2}) /home/runner/work/oh-my-posh/oh-my-posh/src/segment_git.go:274 +0x13b main.(git).setGitStatus(0xc0002700f0) /home/runner/work/oh-my-posh/oh-my-posh/src/segment_git.go:305 +0x3c8 main.(git).string(0xc0002700f0) /home/runner/work/oh-my-posh/oh-my-posh/src/segment_git.go:183 +0xc5 main.(Segment).string(...) /home/runner/work/oh-my-posh/oh-my-posh/src/segment.go:141 main.(Segment).setStringValue(0xc0001d4c00, {0xcd8500, 0xc000078b90}) /home/runner/work/oh-my-posh/oh-my-posh/src/segment.go:297 +0xc5 main.(Block).setStringValues.func1(0x0) /home/runner/work/oh-my-posh/oh-my-posh/src/block.go:87 +0x65 created by main.(*Block).setStringValues /home/runner/work/oh-my-posh/oh-my-posh/src/block.go:85 +0x9d

╭─ pwsh  SpaceEngineers  error 羽0ms⠀     99   8,14:39  ╰─ff

Theme: atomicBit

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

goroutine 118 [running]: runtime/debug.Stack() /opt/hostedtoolcache/go/1.17.3/x64/src/runtime/debug/stack.go:24 +0x65 main.(Segment).setStringValue.func1() /home/runner/work/oh-my-posh/oh-my-posh/src/segment.go:287 +0x58 panic({0xb73cc0, 0x15400b0}) /opt/hostedtoolcache/go/1.17.3/x64/src/runtime/panic.go:1038 +0x215 main.(GitStatus).add(...) /home/runner/work/oh-my-posh/oh-my-posh/src/segment_git.go:30 main.(git).setGitStatus.func1({0xc00044c079, 0x2}) /home/runner/work/oh-my-posh/oh-my-posh/src/segment_git.go:274 +0x13b main.(git).setGitStatus(0xc000416000) /home/runner/work/oh-my-posh/oh-my-posh/src/segment_git.go:305 +0x3c8 main.(git).string(0xc000416000) /home/runner/work/oh-my-posh/oh-my-posh/src/segment_git.go:183 +0xc5 main.(Segment).string(...) /home/runner/work/oh-my-posh/oh-my-posh/src/segment.go:141 main.(Segment).setStringValue(0xc00024f000, {0xcd8500, 0xc000078b90}) /home/runner/work/oh-my-posh/oh-my-posh/src/segment.go:297 +0xc5 main.(Block).setStringValues.func1(0x0) /home/runner/work/oh-my-posh/oh-my-posh/src/block.go:87 +0x65 created by main.(*Block).setStringValues /home/runner/work/oh-my-posh/oh-my-posh/src/block.go:85 +0x9d

╭─[vegar@Photo-PC]─[SpaceEngineers] ()─[ 99%]─[ 8,14:39] ╰─[error]-ff

JanDeDobbeleer commented 2 years ago

The fix is building

JanDeDobbeleer commented 2 years ago

Status update: GitHub Releases is experiencing issues, I unlisted this release and the Powershell module so stay tuned.

JanDeDobbeleer commented 2 years ago

Status update: fix is available

Kyllingene commented 2 years ago

I have the same issue, just downloaded oh-my-posh today; it happens on all themes I've tried (default, the bubbles family, atomic, etc.). I'm using it in Nu on Windows Terminal.

JanDeDobbeleer commented 2 years ago

@Kyllingene can you share your config ?

Kyllingene commented 2 years ago

My Nu config is just this: prompt = "(oh-my-posh --config C:/Users/josia/scoop/apps/oh-my-posh/current/themes/<theme>.json | str collect)"

JanDeDobbeleer commented 2 years ago

@Kyllingene do you also have a stacktrace? Because it should print it (provided oh-my-posh is up to date).

Kyllingene commented 2 years ago
goroutine 19 [running]:
runtime/debug.Stack()
        /opt/hostedtoolcache/go/1.17.7/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:332 +0x58
panic({0xd0fbe0, 0x17cdb50})
        /opt/hostedtoolcache/go/1.17.7/x64/src/runtime/panic.go:1038 +0x215
strings.Count({0x0, 0xc00002e0c0}, {0xda423d, 0xc00002e090})
        /opt/hostedtoolcache/go/1.17.7/x64/src/strings/strings.go:47 +0x50
strings.Replace({0x0, 0x0}, {0xda423d, 0x1}, {0xda4227, 0x1}, 0xffffffffffffffff)
        /opt/hostedtoolcache/go/1.17.7/x64/src/strings/strings.go:930 +0xcc
strings.ReplaceAll(...)
        /opt/hostedtoolcache/go/1.17.7/x64/src/strings/strings.go:964
oh-my-posh/environment.DirMatchesOneOf({0xec29f8, 0xc0000dade0}, {0x0, 0xe}, {0x1839080, 0x0, 0x0})
        /home/runner/work/oh-my-posh/oh-my-posh/src/environment/shell.go:699 +0x76
oh-my-posh/engine.(*Segment).cwdExcluded(0xc0001c9e60)
        /home/runner/work/oh-my-posh/oh-my-posh/src/engine/segment.go:200 +0xde
oh-my-posh/engine.(*Segment).shouldIncludeFolder(0xc0001c9e60)
        /home/runner/work/oh-my-posh/oh-my-posh/src/engine/segment.go:173 +0x2c
oh-my-posh/engine.(*Segment).renderText(0xc0001c9e60, {0xec29f8, 0xc0000dade0})
        /home/runner/work/oh-my-posh/oh-my-posh/src/engine/segment.go:338 +0x7b
oh-my-posh/engine.(*Block).renderSegmentsText.func1(0x0)
        /home/runner/work/oh-my-posh/oh-my-posh/src/engine/block.go:87 +0x65
created by oh-my-posh/engine.(*Block).renderSegmentsText
        /home/runner/work/oh-my-posh/oh-my-posh/src/engine/block.go:85 +0x9d
JanDeDobbeleer commented 2 years ago

@Kyllingene check #1907, fix incoming.

Kyllingene commented 2 years ago

Ok, thanks!

github-actions[bot] commented 9 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.