-
I'm still learning hammerspoon API. I've got a config autoreload workflow working solidly now and i'd like to make it robust against all syntax and logic errors inside so that auto reload won't break and need manual re-load if I happen to save the hammerspoon init.lua with a syntax error. Generally the approach would look something like putting in a try catch around the reload call, and if the load fails, fall back to a load of a config that is known to work (and contains e.g. only config autoreload behavior). I'll try it out and see how it goes. So far it seems there isn't a way to give an alternate config file path to reload(). But my strategy for this right now is since my config file is already a symlink i'd just retarget this symlink to a known safe config temporarily, and add some more symlink munging logic in the alternate config code. That's all assuming an error in loading could be captured via an exception handler from the original config and the original config would keep executing (feels doubtful so far imo). |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
Your hunch at the end there is right - there's no fallback if I think the only way to make it truly resilient would be for the auto-reload functionality to be built into Hammerspoon itself, rather than implemented in Lua. |
Beta Was this translation helpful? Give feedback.
-
Off the top of my head, this might be challenging. You can change the default init script by changing the value of the setting "MJConfigScript", either with And as mentioned above, there is not functionality for "catching" a reload. You could have the initial local status, err = pcall(dofile, "testing-init.lua")
if not status then
print(string.format("testing init file failed with: %s", err))
print("Loading fallback...")
dofile("fallback-init.lua")
end This is just the bare-bones, but the key takeaway is the Beyond that, yeah, I think @cmsj is right and we'd need some way to syntax check the new files before actually begining the reload process. |
Beta Was this translation helpful? Give feedback.
Code is now: