NvChad / base46

NvChad's base46 theme plugin with caching ( Total re-write )
Other
209 stars 204 forks source link

Toggle theme fails when `chadrc.ui` is `nil` #325

Closed lingling9000 closed 3 months ago

lingling9000 commented 3 months ago

After the recent move of all theming options into chadrc.base46 table I moved forward and migrated right ahead.

As I didn't modified any ui options I do not have a ui table in my chadrc.lua.

But this breaks the toggle theme function with following error:

E5108: Error executing lua: ...e/user/.local/share/nvim/lazy/base46/lua/base46/init.lua:207: attempt to index field 'ui' (a nil value)  
stack traceback:                                                                                                                        
        ...e/user/.local/share/nvim/lazy/base46/lua/base46/init.lua:207: in function <...e/user/.local/share/nvim/lazy/base46/lua/base46
/init.lua:189>

Following line throws that error:

https://github.com/NvChad/base46/blob/c61d75292f3efecb289c7f27b188619b012820a8/lua/base46/init.lua#L207

When removing the conditional for chadrc.ui.theme the error is resolved:

local old_theme = chadrc.base46.theme

But as you want to provide backwards compability with chardrc.ui this may not desirable. Maybe define it as empty table if it is not given?

It need to be noted that a new user using the starter configuration will probably face this problem, as the starter config does not have a chadrc.ui table defined by default.

I created a minimal example to demonstrate the issue:

I assume that a new user would try something like this to enable theme toggling, but that failes: https://github.com/lingling9000/nvchad-toggle-theme-issue-demo/commit/1304b8eba8119bf41af860c5aa12a2fb75fa72a4