agzam / spacehammer

Hammerspoon config inspired by Spacemacs
MIT License
556 stars 70 forks source link

bad argument #1 to 'for iterator' (table expected, got nil) #145

Closed xiaobing-huang closed 1 year ago

xiaobing-huang commented 2 years ago

After start my computer, activate modal, got below error:

2021-10-27 09:42:39: 09:42:39 apps.fnl: app is now: nil 2021-10-27 09:42:39: app is now: nil 2021-10-27 09:42:39: 09:42:39 ERROR: LuaSkin: hs.application.watcher callback: ...on.app/Contents/Resources/extensions/hs/fnutils/init.lua:265: bad argument #1 to 'for iterator' (table expected, got nil) stack traceback: [C]: in function 'next' ...on.app/Contents/Resources/extensions/hs/fnutils/init.lua:265: in function 'hs.fnutils.find' (...tail calls...) ./lib/apps.fnl:65: in local 'tx_fn' ./lib/statemachine.fnl:30: in function 'lib.statemachine.send' (...tail calls...) 2021-10-27 09:43:38: app is now: nil 2021-10-27 09:43:38: app is now: nil 2021-10-27 09:43:38: app is now: nil 2021-10-27 09:43:38: 09:43:38 ERROR: LuaSkin: hs.application.watcher callback: ...on.app/Contents/Resources/extensions/hs/fnutils/init.lua:265: bad argument #1 to 'for iterator' (table expected, got nil) stack traceback: [C]: in function 'next' ...on.app/Contents/Resources/extensions/hs/fnutils/init.lua:265: in function 'hs.fnutils.find' (...tail calls...) ./lib/apps.fnl:65: in local 'tx_fn' ./lib/statemachine.fnl:30: in function 'lib.statemachine.send' (...tail calls...)

the main modal won't appear, then open hammerspoon console, main modal appears.

Grazfather commented 2 years ago

Can you please share your config and the commit hash of spacehammer:

cd ~/.hammerspoon
git rev-parse @
jaidetree commented 2 years ago

Get that error too but doesn't seem to be preventing any functionality:

2021-10-26 22:09:06: 22:09:06 ERROR:   LuaSkin: hs.application.watcher callback: ...on.app/Contents/Resources/extensions/hs/fnutils/init.lua:265: bad argument #1 to 'for iterator' (table expected, got nil)
stack traceback:
    [C]: in function 'next'
    ...on.app/Contents/Resources/extensions/hs/fnutils/init.lua:265: in function 'hs.fnutils.find'
    (...tail calls...)
    ./lib/apps.fnl:65: in local 'tx_fn'
    ./lib/statemachine.fnl:29: in function 'lib.statemachine.send'
xiaobing-huang commented 2 years ago

Can you please share your config and the commit hash of spacehammer:

cd ~/.hammerspoon
git rev-parse @

spacehammer config

and commit hash is: 85d6f263b50ea7079aecceaf9caa3232c0dbad76

Grazfather commented 2 years ago

Looks like a bug in modal's active->submenu, specifically the state's :menu should be a table, but we set it to :nil sometimes, so prev-menu.items is nil in this line

(fn active->submenu
  [state action menu-key]
  "
  Enter a submenu like entering into the Window menu from the default main menu.
  Takes the current menu state table and the submenu key as 'extra'.
  Returns updated menu state
  "
  (let [{:config config
         :menu prev-menu} state.context
        menu (if menu-key
                 (find (by-key menu-key) prev-menu.items)            ; prev-menu is probably :nil so .items is nil
                 config)]
    {:state {:current-state :submenu
             :context (merge state.context {:menu menu})}
     :effect :open-submenu}))
Grazfather commented 2 years ago

I think that this'll fix it.

diff --git a/lib/modal.fnl b/lib/modal.fnl
index e97c2fc..625144d 100644
--- a/lib/modal.fnl
+++ b/lib/modal.fnl
@@ -317,7 +317,7 @@ switching menus in one place which is then powered by config.fnl.
   Returns updated modal state machine state table.
   "
   {:state  {:current-state :idle
-            :context (merge state.context {:menu :nil
+            :context (merge state.context {:menu state.context.config
                                            :history []})}
    :effect :close-modal-menu})

@@ -488,7 +488,7 @@ switching menus in one place which is then powered by config.fnl.
   "
   (let [initial-context {:config config
                          :history []
-                         :menu :nil}
+                         :menu config}
         template {:state {:current-state :idle
                           :context initial-context}
                   :states states

Could someone please test it?

jaidetree commented 2 years ago

Just applied it, will follow up if I see issues in the log

Grazfather commented 2 years ago

Did you happen to see anything?

xiaobing-huang commented 2 years ago

Did you happen to see anything?

sorry for late feedback, the error still occurs.

2021-11-06 07:53:17: 07:53:17 ERROR: LuaSkin: hs.application.watcher callback: ...on.app/Contents/Resources/extensions/hs/fnutils/init.lua:265: bad argument #1 to 'for iterator' (table expected, got nil) stack traceback: [C]: in function 'next' ...on.app/Contents/Resources/extensions/hs/fnutils/init.lua:265: in function 'hs.fnutils.find' (...tail calls...) ./lib/apps.fnl:65: in local 'tx_fn' ./lib/statemachine.fnl:29: in function 'lib.statemachine.send' (...tail calls...) 2021-11-06 07:53:44: 07:53:44 apps.fnl: app is now: nil 2021-11-06 07:53:44: app is now: nil 2021-11-06 07:53:44: 07:53:44 ERROR: LuaSkin: hs.application.watcher callback: ./lib/apps.fnl:154: table index is nil stack traceback: ./lib/apps.fnl:154: in local 'sub' ./lib/statemachine.fnl:44: in function 'lib.statemachine.send' (...tail calls...)

xiaobing-huang commented 2 years ago

just pulled the latest changes, will see whether the same error still occur.

Grazfather commented 2 years ago

I have not merged this fix. You would have to manually apply the change I mention above to test the fix.

xiaobing-huang commented 2 years ago

applied the changes, will let you know whether it works.

Grazfather commented 2 years ago

Any luck?

xiaobing-huang commented 2 years ago

Any luck?

this error seems caused by line 189 in apps.fnl

the variable apps is nil, if i change apps to state.context.apps, the error will be gone.

Grazfather commented 2 years ago

I pushed a PR to fix the second error, but note that it's not the same as your original error.

Grazfather commented 2 years ago

@eccentric-j did my fix above fix the error you were having? Note that that error is not the same as the one fixed in #153, which is here:

2021-11-06 07:53:44: 07:53:44 ERROR: LuaSkin: hs.application.watcher callback: ./lib/apps.fnl:154: table index is nil
stack traceback:
./lib/apps.fnl:154: in local 'sub'
./lib/statemachine.fnl:44: in function 'lib.statemachine.send'
(...tail calls...)
jaidetree commented 2 years ago

Just pulled, will let you know

jaidetree commented 1 year ago

Haven't seen this since so I think it's fixed