chrisant996/clink-flex-prompt

k8s in prompt causing error

Closed this issue · 9 comments

i have flexprompt_config.lua like below

flexprompt.settings.left_prompt = flexprompt.settings.left_prompt .. "{k8s}{python}"

and everything else is default setting.
when i open my cmd, im getting this error

 C:\Windows\System32 ﴱ error running kubectl.exe ❯ set KUBECONFIG=C:\kube\ml_lab.yaml                           exit  130
 C:\Windows\System32 ﴱ error running kubectl.exe ❯                                                              exit  130
prompt filter failed:
...s\mmanivannan\AppData\Local\clink\flexprompt_modules.lua:1100: attempt to concatenate local 'text' (a nil value)
stack traceback:
        C:\Users\mmanivannan\AppData\Local\clink\flexprompt.lua:1057: in function 'render_module'
        C:\Users\mmanivannan\AppData\Local\clink\flexprompt.lua:1127: in function 'render_modules'
        C:\Users\mmanivannan\AppData\Local\clink\flexprompt.lua:1222: in function 'render_prompts'
        C:\Users\mmanivannan\AppData\Local\clink\flexprompt.lua:1380: in function <C:\Users\mmanivannan\AppData\Local\clink\flexprompt.lua:1379>
        {prompt.lua}: in function <{prompt.lua}:72>
        [C]: in function 'xpcall'
        {prompt.lua}: in function <{prompt.lua}:53>
        (...tail calls...)
        [C]: in function 'refilterprompt'
        {prompt.lua}: in function <{prompt.lua}:354>
        [C]: in function 'xpcall'
        {coroutines.lua}: in function <{coroutines.lua}:260>

ERROR IN LUA PROMPT FILTER
C:\Windows\System32>

any idea what i am doing wrong ?

@manojmanivannan The command kubectl.exe config view --minify must not be printing a namespace: line. The intent was to use default as the namespace when kubectl doesn't report one, but there's a bug and it accidentally loses the default string.

I've pushed a fix, and published v0.17 of clink-flex-prompt.

But:

It looks like you're using a copy of clink-flex-prompt from between Aug 31, 2022 and Oct 20, 2022 -- probably v0.11 (that's the time range when line 1100 would be the line number reported in the error message).

There have been a lot of internal changes in the past 1.5 years since v0.11, so after you pull the latest you should use flexprompt configure again to make sure that the configuration is up to date. Otherwise you might lose some nerdfont or powerline symbols or colors or etc.

hi @chrisant996 thanks a lot for you response. i updated to the latest flex-prompt and this issue is solved. However, it would be nice if it does not show any error (error running kubectl.exe) if no KUBECONFIG variable is set when opening a new terminal

Microsoft Windows [Version 10.0.19045.4046]
(c) Microsoft Corporation. All rights reserved.

Clink v1.6.9.242b68
Copyright (c) 2012-2018 Martin Ridgers
Portions Copyright (c) 2020-2024 Christopher Antos
https://github.com/chrisant996/clink
📁 C:\Users\mmanivannan · 󰠳 error running kubectl.exe ❯ k.ml                                                                                                                                                                                   Wed 08:58 🕒
Context "central" modified.
📁 C:\Users\mmanivannan · 󰠳 central:default❯   

i have an alias, k.ml which once triggered sets the KUBECONFIG, then the behavior seems fine.

@manojmanivannan my understanding was that the env var is not necessarily required for all possible user configurations. In other words, that condition doesn't seem quite accurate/complete for when to suppress the error message.

What if instead it showed the k8s icon with simply "error"?

Also, is there a reason to not configure the env var so it's always set?

I usually have multiple k8s cluster to work with, so i set them when necessary. I suppose I could set one of them as default

@manojmanivannan

What if instead it showed the k8s icon with simply "error"?

Yes. That would be nice or simply No Context

Yes. That would be nice or simply No Context

But how can it determine that the reason for failure is "no context"? It would be unreasonable to claim that all errors are caused by "no context". E.g. what if kubectl.exe doesn't exist, or isn't found on the PATH, or there isn't sufficient permission to access the exe, or many other kinds of failures. It's better to be accurate.

oh right, i agree. a simple error should be sufficient.

The error message has been shortened. You can git pull to get it.

(Or if you installed via e.g. scoop and are already updated to v0.17, then you could manually download the flexprompt_modules.lua file directly. I don't plan to publish a v0.18 until there's more to include, though.)