Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
xiaobing-huang opened this issue Oct 27, 2021 · 17 comments
Closed

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

xiaobing-huang opened this issue Oct 27, 2021 · 17 comments

Comments

@xiaobing-huang
Copy link

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
Copy link
Collaborator

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

cd ~/.hammerspoon
git rev-parse @

@jaidetree
Copy link
Collaborator

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
Copy link
Author

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

cd ~/.hammerspoon
git rev-parse @

spacehammer config

and commit hash is:
85d6f26

@Grazfather
Copy link
Collaborator

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
Copy link
Collaborator

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
Copy link
Collaborator

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

@Grazfather
Copy link
Collaborator

Did you happen to see anything?

@xiaobing-huang
Copy link
Author

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
Copy link
Author

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

@Grazfather
Copy link
Collaborator

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

@xiaobing-huang
Copy link
Author

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

@Grazfather
Copy link
Collaborator

Any luck?

@xiaobing-huang
Copy link
Author

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
Copy link
Collaborator

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

@Grazfather
Copy link
Collaborator

@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
Copy link
Collaborator

Just pulled, will let you know

@jaidetree
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants