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

tooltip block fails to render #1701

Closed noam-codefresh closed 2 years ago

noam-codefresh commented 2 years ago

Code of Conduct

What happened?

whenever i put in the required hint for a toolTip segment, i get the following error stacktrace:

gitpanic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x28 pc=0x44f84ff]

goroutine 1 [running]:
oh-my-posh/engine.(*Block).writePowerline.func1(...)
        /private/tmp/oh-my-posh-20220205-91691-1rswyz8/oh-my-posh-7.9.0/src/engine/block.go:128
oh-my-posh/engine.(*Block).writePowerline(0x7ff7bfeff7c3, 0x3)
        /private/tmp/oh-my-posh-20220205-91691-1rswyz8/oh-my-posh-7.9.0/src/engine/block.go:135 +0x1f
oh-my-posh/engine.(*Block).renderSegments(0xc00015da88)
        /private/tmp/oh-my-posh-20220205-91691-1rswyz8/oh-my-posh-7.9.0/src/engine/block.go:105 +0xd3
oh-my-posh/engine.(*Engine).RenderTooltip(0xc00015ddd0, {0x7ff7bfeff7d1, 0x0})
        /private/tmp/oh-my-posh-20220205-91691-1rswyz8/oh-my-posh-7.9.0/src/engine/engine.go:247 +0x2c5
main.main()
        /private/tmp/oh-my-posh-20220205-91691-1rswyz8/oh-my-posh-7.9.0/src/main.go:213 +0x10c5

looking at the code, it seems like the tooltip just created a block with a single segment, and later calls writePowerline. this call tries to access b.activeSegment.Style while b.activeSegment is nil, which panics. tooltips were working correctly for me on v7.8.1 (I think), and i started having this bug since v7.8.3. i tried looking for the faulty commit, but couldn't see anything related. but i guess it should be in there somewhere.

Theme

{
  "$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
  "blocks": [
    {
      "alignment": "left",
      "segments": [
        {
          "background": "#546E7A",
          "foreground": "#26C6DA",
          "powerline_symbol": "\ue0b0",
          "properties": {
            "template": " {{ if .WSL }}WSL at {{ end }}{{.Icon}} "
          },
          "style": "powerline",
          "type": "os"
        },
        {
          "background": "#0077c2",
          "foreground": "#ffffff",
          "powerline_symbol": "\ue0b0",
          "properties": {
            "template": " {{ .Name }} "
          },
          "style": "powerline",
          "type": "shell"
        },
        {
          "background": "#ffff66",
          "foreground": "#111111",
          "powerline_symbol": "\ue0b0",
          "properties": {
            "template": " \uf0e7 "
          },
          "style": "powerline",
          "type": "root"
        },
        {
          "background": "#91ddff",
          "foreground": "#100e23",
          "powerline_symbol": "\ue0b0",
          "properties": {
            "folder_icon": "\uf115",
            "folder_separator_icon": "\ue0b1",
            "style": "short",
            "template": " {{ .Path }} "
          },
          "style": "powerline",
          "type": "path"
        },
        {
          "background": "#ffffff",
          "foreground": "#4A94E5",
          "powerline_symbol": "\ue0b0",
          "properties": {
            "template": " {{if .Env.DOCKER_MACHINE_NAME }}\uf308{{end}} "
          },
          "style": "powerline",
          "type": "text"
        },
        {
          "background": "#ffeb3b",
          "background_templates": [
            "{{if eq \"Charging\" .State.String}}#40c4ff{{end}}",
            "{{if eq \"Discharging\" .State.String}}#ff5722{{end}}",
            "{{if eq \"Full\" .State.String}}#4caf50{{end}}"
          ],
          "foreground": "#193549",
          "powerline_symbol": "\ue0b0",
          "properties": {
            "charged_icon": "\ue22f ",
            "charging_icon": "\ue234 ",
            "discharging_icon": "\ue231 ",
            "template": " {{ if not .Error }}{{.Icon}}{{.Percentage}}{{ end }}\uf295 "
          },
          "style": "powerline",
          "type": "battery"
        },
        {
          "background": "#00897b",
          "background_templates": [
            "{{ if gt .Code 0 }}#e91e63{{ end }}"
          ],
          "foreground": "#ffffff",
          "powerline_symbol": "\ue0b0",
          "properties": {
            "always_enabled": true,
            "template": " \ue23a "
          },
          "style": "powerline",
          "type": "exit"
        }
      ],
      "type": "prompt"
    }
  ],
  "console_title": true,
  "console_title_style": "template",
  "console_title_template": "{{if .Root}}\uf0e7 {{end}}{{.User}}@{{.Host}} {{.Folder}}",
  "final_space": true,
  "tooltips": [
    {
      "background": "#FFA400",
      "foreground": "#ffffff",
      "leading_diamond": "\ue0b6",
      "properties": {
        "template": " \ue7ad {{.Profile}}{{if .Region}}@{{.Region}}{{end}} "
      },
      "style": "diamond",
      "tips": [
        "aws"
      ],
      "trailing_diamond": "\ue0b4",
      "type": "aws"
    },
    {
      "type": "git",
      "tips": [
        "git"
      ],
      "style": "diamond",
      "foreground": "#193549",
      "background": "#fffb38",
      "leading_diamond": "",
      "trailing_diamond": "",
      "background_templates": [
        "{{ if or (.Working.Changed) (.Staging.Changed) }}#FFEB3B{{ end }}",
        "{{ if and (gt .Ahead 0) (gt .Behind 0) }}#FFCC80{{ end }}",
        "{{ if gt .Ahead 0 }}#B388FF{{ end }}",
        "{{ if gt .Behind 0 }}#B388FB{{ end }}"
      ],
      "powerline_symbol": "\ue0b0",
      "properties": {
        "fetch_stash_count": true,
        "fetch_status": true,
        "fetch_upstream_icon": true,
        "fetch_worktree_count": true,
        "template": " {{ .UpstreamIcon }}{{ .HEAD }}{{ .BranchStatus }}{{ 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 }} "
      }
    },
    {
      "background": "#7FD5EA",
      "foreground": "#ffffff",
      "leading_diamond": "\ue0b6",
      "properties": {
        "template": " \ufcd1 {{ if .Error }}{{ .Error }}{{ else }}{{ .Full }}{{ end }} "
      },
      "style": "diamond",
      "tips": [
        "go"
      ],
      "trailing_diamond": "\ue0b4",
      "type": "go"
    },
    {
      "background": "#c386f1",
      "foreground": "#ffffff",
      "leading_diamond": "\ue0b6",
      "properties": {
        "cache_timeout": 5,
        "http_timeout": 1000,
        "template": " {{ .IP }} "
      },
      "style": "diamond",
      "tips": [
        "ip"
      ],
      "trailing_diamond": "\ue0b0",
      "type": "ipify"
    },
    {
      "background": "#ebcc34",
      "foreground": "#000000",
      "leading_diamond": "\ue0b6",
      "properties": {
        "template": " \ufd31 {{.Context}}{{if .Namespace}} :: {{.Namespace}}{{end}} "
      },
      "style": "diamond",
      "tips": [
        "kubectl",
        "k"
      ],
      "trailing_diamond": "\ue0b4",
      "type": "kubectl"
    },
    {
      "background": "#6CA35E",
      "foreground": "#ffffff",
      "leading_diamond": "\ue0b6",
      "powerline_symbol": "\ue0b0",
      "properties": {
        "fetch_package_manager": true,
        "template": " \ue718 {{ if .PackageManagerIcon }}{{ .PackageManagerIcon }} {{ end }}{{ .Full }} "
      },
      "style": "diamond",
      "tips": [
        "node",
        "npm",
        "nvm",
        "yarn"
      ],
      "trailing_diamond": "\ue0b4",
      "type": "node"
    },
    {
      "background": "#906cff",
      "foreground": "#100e23",
      "powerline_symbol": "\ue0b0",
      "properties": {
        "template": " \ue235 {{ if .Error }}{{ .Error }}{{ else }}{{ if .Venv }}{{ .Venv }} {{ end }}{{ .Full }}{{ end }} "
      },
      "style": "powerline",
      "tips": [
        "py"
      ],
      "type": "python"
    },
    {
      "background": "#8822ee",
      "background_templates": [
        "{{ if (lt .Signal 60) }}#DDDD11{{ else if (lt .Signal 90) }}#DD6611{{ else }}#11CC11{{ end }}"
      ],
      "foreground": "#222222",
      "powerline_symbol": "\ue0b0",
      "properties": {
        "template": " {{ if .Error }}{{ .Error }}{{ else }}\ufaa8 {{ .SSID }} {{ .Signal }}% {{ .ReceiveRate }}Mbps{{ end }} "
      },
      "style": "powerline",
      "tips": [
        "wi"
      ],
      "type": "wifi"
    }
  ],
  "version": 1
}

What OS are you seeing the problem on?

Windows, macOS

Which shell are you using?

zsh, powershell

Log output

Version: 7.9.0

Segments:

ConsoleTitle(true) -   0 ms -
os(true)       -   0 ms -  
shell(true)    -   0 ms -  uni
root(false)    -   0 ms -
path(true)     -   0 ms -  ~source
text(false)    -   0 ms -
battery(true)  -  14 ms -   98
exit(true)     -   1 ms -  

Run duration: 18.086795ms

Cache path: /Users/noamgal/.cache/oh-my-posh

Logs:

2022/02/05 09:11:05 Args duration: 307ns, args:
2022/02/05 09:11:05 Args duration: 143ns, args:
2022/02/05 09:11:05 Args duration: 143ns, args:
2022/02/05 09:11:05 Shell duration: 100ns, args:
2022/02/05 09:11:05 debug: Getenv

2022/02/05 09:11:05 Getenv duration: 4.388µs, args: OMP_CACHE_DISABLED
2022/02/05 09:11:05 Root duration: 1.29µs, args:
2022/02/05 09:11:05 Shell duration: 75ns, args:
2022/02/05 09:11:05 ErrorCode duration: 58ns, args:
2022/02/05 09:11:05 debug: Getenv

2022/02/05 09:11:05 Getenv duration: 1.399µs, args: WSL_DISTRO_NAME
2022/02/05 09:11:05 IsWsl duration: 3.282µs, args:
2022/02/05 09:11:05 debug: Pwd
/Users/noamgal/source
2022/02/05 09:11:05 Pwd duration: 17.278µs, args:
2022/02/05 09:11:05 PathSeperator duration: 75ns, args:
2022/02/05 09:11:05 PathSeperator duration: 43ns, args:
2022/02/05 09:11:05 PathSeperator duration: 42ns, args:
2022/02/05 09:11:05 PathSeperator duration: 44ns, args:
2022/02/05 09:11:05 PathSeperator duration: 45ns, args:
2022/02/05 09:11:05 PathSeperator duration: 44ns, args:
2022/02/05 09:11:05 PathSeperator duration: 44ns, args:
2022/02/05 09:11:05 PathSeperator duration: 43ns, args:
2022/02/05 09:11:05 User duration: 260ns, args:
2022/02/05 09:11:05 Host duration: 10.193µs, args:
2022/02/05 09:11:05 GOOS duration: 74ns, args:
2022/02/05 09:11:05 TemplateCache duration: 70.143µs, args:
2022/02/05 09:11:05 debug: Pwd
/Users/noamgal/source
2022/02/05 09:11:05 Pwd duration: 957ns, args:
2022/02/05 09:11:05 GOOS duration: 40ns, args:
2022/02/05 09:11:05 TemplateCache duration: 188ns, args:
2022/02/05 09:11:05 debug: Pwd
/Users/noamgal/source
2022/02/05 09:11:05 Pwd duration: 1.159µs, args:
2022/02/05 09:11:05 Shell duration: 95ns, args:
2022/02/05 09:11:05 TemplateCache duration: 96ns, args:
2022/02/05 09:11:05 debug: Pwd
/Users/noamgal/source
2022/02/05 09:11:05 Pwd duration: 924ns, args:
2022/02/05 09:11:05 Root duration: 710ns, args:
2022/02/05 09:11:05 debug: Pwd
/Users/noamgal/source
2022/02/05 09:11:05 Pwd duration: 693ns, args:
2022/02/05 09:11:05 debug: Pwd
/Users/noamgal/source
2022/02/05 09:11:05 Pwd duration: 546ns, args:
2022/02/05 09:11:05 Args duration: 73ns, args:
2022/02/05 09:11:05 debug: Pwd
/Users/noamgal/source
2022/02/05 09:11:05 Pwd duration: 556ns, args:
2022/02/05 09:11:05 GOOS duration: 58ns, args:
2022/02/05 09:11:05 GOOS duration: 42ns, args:
2022/02/05 09:11:05 PathSeperator duration: 61ns, args:
2022/02/05 09:11:05 GOOS duration: 58ns, args:
2022/02/05 09:11:05 debug: Getenv

2022/02/05 09:11:05 Getenv duration: 837ns, args: WSL_DISTRO_NAME
2022/02/05 09:11:05 IsWsl duration: 2.388µs, args:
2022/02/05 09:11:05 StackCount duration: 98ns, args:
2022/02/05 09:11:05 TemplateCache duration: 93ns, args:
2022/02/05 09:11:05 debug: Pwd
/Users/noamgal/source
2022/02/05 09:11:05 Pwd duration: 872ns, args:
2022/02/05 09:11:05 TemplateCache duration: 65ns, args:
2022/02/05 09:11:05 debug: Pwd
/Users/noamgal/source
2022/02/05 09:11:05 Pwd duration: 864ns, args:
2022/02/05 09:11:05 BatteryInfo duration: 13.147194ms, args:
2022/02/05 09:11:05 TemplateCache duration: 303ns, args:
2022/02/05 09:11:05 TemplateCache duration: 161ns, args:
2022/02/05 09:11:05 TemplateCache duration: 143ns, args:
2022/02/05 09:11:05 TemplateCache duration: 106ns, args:
2022/02/05 09:11:05 TemplateCache duration: 82ns, args:
2022/02/05 09:11:05 TemplateCache duration: 100ns, args:
2022/02/05 09:11:05 TemplateCache duration: 71ns, args:
2022/02/05 09:11:05 debug: Pwd
/Users/noamgal/source
2022/02/05 09:11:05 Pwd duration: 1.838µs, args:
2022/02/05 09:11:05 ErrorCode duration: 287ns, args:
2022/02/05 09:11:05 TemplateCache duration: 182ns, args:
2022/02/05 09:11:05 TemplateCache duration: 143ns, args:
2022/02/05 09:11:05 TemplateCache duration: 120ns, args:
2022/02/05 09:11:05 TemplateCache duration: 93ns, args:
2022/02/05 09:11:05 TemplateCache duration: 70ns, args:
2022/02/05 09:11:05 TemplateCache duration: 76ns, args:
2022/02/05 09:11:05 debug: Getenv

2022/02/05 09:11:05 Getenv duration: 2.236µs, args: XDG_CACHE_HOME
2022/02/05 09:11:05 CachePath duration: 31.99µs, args:
JanDeDobbeleer commented 2 years ago

@noam-codefresh I'll see if I can reproduce this. Should be fairly straightforward.

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