JanDeDobbeleer / oh-my-posh

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

fatal error rendering exit segment:assignment to entry in nil map #1366

Closed akunzai closed 2 years ago

akunzai commented 2 years ago

Code of Conduct

What happened?

Without properties in exit segment,

When last shell command exit with non-zero code,

the exit segment will run into fatal error.

Theme

{
  "$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
  "blocks": [
    {
      "alignment": "left",
      "newline": true,
      "segments": [
        {
          "type": "exit",
          "style": "plain",
          "foreground": "red"
        },
        {
          "type": "text",
          "style": "plain",
          "foreground": "default",
          "properties": {
            "text": "$"
          }
        }
      ],
      "type": "prompt"
    }
  ]
}

What OS are you seeing the problem on?

Linux, macOS

Which shell are you using?

zsh, bash

Log output

$ foobar123
foobar123: command not found

oh-my-posh fatal error rendering exit segment:assignment to entry in nil map

goroutine 6 [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:284 +0x58
panic({0x93aa00, 0xa68e80})
    /opt/hostedtoolcache/go/1.17.3/x64/src/runtime/panic.go:1038 +0x215
main.(*exit).deprecatedString(0xc000172690)
    /home/runner/work/oh-my-posh/oh-my-posh/src/segment_deprecated.go:171 +0xf1
main.(*exit).getFormattedText(0xc000172690)
    /home/runner/work/oh-my-posh/oh-my-posh/src/segment_exit.go:34 +0x132
main.(*exit).string(0xc000172690)
    /home/runner/work/oh-my-posh/oh-my-posh/src/segment_exit.go:21 +0x19
main.(*Segment).string(...)
    /home/runner/work/oh-my-posh/oh-my-posh/src/segment.go:141
main.(*Segment).setStringValue(0xc00013c600, {0xa8b600, 0xc00006cbe0})
    /home/runner/work/oh-my-posh/oh-my-posh/src/segment.go:294 +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
lnu commented 2 years ago

linked to https://github.com/JanDeDobbeleer/oh-my-posh/pull/1320 in this scenario, properties is null. Temporary workaround is to add an empty properties block:

        {
          "type": "exit",
          "style": "plain",
          "foreground": "red",
          "properties": {
          }
        }

One way to solve it is to initialize the map by default in segment.go mapSegmentWithWriter.

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.