spacehammer icon indicating copy to clipboard operation
spacehammer copied to clipboard

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

Open xiaobing-huang opened this issue 4 years ago • 16 comments

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.

xiaobing-huang avatar Oct 27 '21 02:10 xiaobing-huang

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

cd ~/.hammerspoon
git rev-parse @

Grazfather avatar Oct 27 '21 02:10 Grazfather

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'

jaidetree avatar Oct 27 '21 04:10 jaidetree

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

cd ~/.hammerspoon
git rev-parse @

spacehammer config

and commit hash is: 85d6f263b50ea7079aecceaf9caa3232c0dbad76

xiaobing-huang avatar Oct 27 '21 05:10 xiaobing-huang

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 avatar Oct 27 '21 12:10 Grazfather

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?

Grazfather avatar Oct 28 '21 18:10 Grazfather

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

jaidetree avatar Oct 28 '21 19:10 jaidetree

Did you happen to see anything?

Grazfather avatar Nov 05 '21 23:11 Grazfather

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 avatar Nov 06 '21 01:11 xiaobing-huang

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

xiaobing-huang avatar Nov 06 '21 02:11 xiaobing-huang

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

Grazfather avatar Nov 06 '21 14:11 Grazfather

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

xiaobing-huang avatar Nov 07 '21 12:11 xiaobing-huang

Any luck?

Grazfather avatar Nov 20 '21 22:11 Grazfather

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.

xiaobing-huang avatar Nov 21 '21 12:11 xiaobing-huang

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

Grazfather avatar Nov 21 '21 21:11 Grazfather

@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...)

Grazfather avatar Nov 22 '21 13:11 Grazfather

Just pulled, will let you know

jaidetree avatar Nov 22 '21 19:11 jaidetree

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

jaidetree avatar Apr 21 '23 05:04 jaidetree