pkulchenko / ZeroBraneStudio

Lightweight Lua-based IDE for Lua with code completion, syntax highlighting, live coding, remote debugger, and code analyzer; supports Lua 5.1, 5.2, 5.3, 5.4, LuaJIT and other Lua interpreters on Windows, macOS, and Linux
http://studio.zerobrane.com/
Other
2.6k stars 519 forks source link

Permission error on Arch Linux: src/util.lua:457: attempt to index a nil value (field 'en') #1091

Closed ComputerNerd closed 3 years ago

ComputerNerd commented 3 years ago

I installed ZeroBrane on Arch Linux using zerobrane-studio-git (to ensure I'm running the latest code and not reporting an issue that was already fixed in an earlier commit) and I receive the following error when I press the stop debugging button.

Lua: Error while running chunk
src/util.lua:457: attempt to index a nil value (field 'en')
stack traceback:
    src/util.lua:457: in function 'TR'
    src/editor/debugger.lua:1727: in method 'teardown'
    src/editor/debugger.lua:1027: in method 'terminate'
    src/editor/debugger.lua:1716: in method 'Stop'
    src/editor/menu_project.lua:361: in function <src/editor/menu_project.lua:361>
    [C]: in method 'MainLoop'
    src/main.lua:884: in main chunk
    [C]: in ?

Note that I did modify the PKGBUILD to use wxlua instead of wxlua-git but I doubt that would have anything to do with it.

I tried to troubleshoot this. I made util.lua require serpent and then I ran serpent.dump on messages and it seemed empty. It just gave me {} (and the code to return that value of course). I'm not sure what's going on.

pkulchenko commented 3 years ago

@ComputerNerd, thank you for the report. It's a bit strange, as messages.en value is populated based on cfg/i18n/en.lua file, which appears to indicate that it's missing. Do you get Error while loading file... message when you are loading the IDE?

Can you try the following patch and let me know the result (the line numbers may be a bit off, but it only adds a check for messages.en):

diff --git a/src/util.lua b/src/util.lua
index d954763d..d0c63bdf 100644
--- a/src/util.lua
+++ b/src/util.lua
@@ -453,7 +462,7 @@ function TR(msg, count)
   -- if there is count and no corresponding message, then
   -- get the message from the (default) english language,
   -- otherwise the message is not going to be pluralized properly
-  if count and (not message or type(message) == 'table' and not next(message)) then
+  if count and messages.en and (not message or type(message) == 'table' and not next(message)) then
     message, counter = messages.en[msg], messages.en[0]
   end
   return count and counter and message and type(message) == 'table'
pkulchenko commented 3 years ago

Note that I did modify the PKGBUILD to use wxlua instead of wxlua-git but I doubt that would have anything to do with it.

I don't think it matters in this case, but there was another strange error on Arch Linux that I couldn't explain (#995; the one on wx.wxArtProvider.GetBitmap). Not sure what it means, but in this case it may point to the package not including needed i18n files. The patch I provided should handle that case more gracefully.

ComputerNerd commented 3 years ago

Thank you for the patch. I applied it and now it seems to work just fine or at-least I don't receive the error.

I do receive an error related to i18n:

Error while loading file: 'cannot open cfg/i18n/en.lua: Permission denied'.

The interesting thing is when I run stat on both src/util.lua and cfg/i18n/en.lua I get 644 for both of them. I tried running chmod 777 on cfg/i18n/en.lua and that didn't fix it. I also tried chown myusername cfg/i18n/en.lua and even combined with the 777 permissions that didn't work. Could it be looking in the wrong folder?

pkulchenko commented 3 years ago

Could it be looking in the wrong folder?

Possibly. How are you launching the application? it would be looking in the cfg folder that is next to the src folder where you applied the changes.

Thank you for the patch. I applied it and now it seems to work just fine or at-least I don't receive the error.

Ok; I'll apply the patch then. Yes, it will work, just won't do translations for messages with multiple instances (like X instances).

ComputerNerd commented 3 years ago

The way I'm running it is by running the zbstudio command in a terminal. The zbstudio command does the following:

#!/usr/bin/env sh
CWD=$(pwd)
cd "/usr/share/zbstudio"
exec /usr/bin/lua src/main.lua zbstudio -cwd "$CWD" "$@"

Also I should mention thank you for all you do on ZeroBrane. I'm new to the editor but I am liking it a lot already especially after getting past this error. It's very nice being able to step through Lua scripts instead of "debugging" using the print functions and the remote debugging works great. I was able to debug the Lua code in my program which embeds Lua.

pkulchenko commented 3 years ago

Great to hear you like it; thank you for the feedback!

Error while loading file: 'cannot open cfg/i18n/en.lua: Permission denied'. cd "/usr/share/zbstudio"

So the full file path would be /usr/share/zbstudio/cfg/i18n/en.lua; is that the one you were checking? Maybe the installation script didn't adjust the permissions on it?

ComputerNerd commented 3 years ago

Yes you are right. That was the issue. It turns out that the cfg folder had 644 permissions instead of 755 like all the other folders above it did.

I ran

chmod 755 /usr/share/zbstudio/cfg/

and that fixed the loading issue.

Looking in the PKGBUILD file it turns out that this line is in the file:

install -dm644 "$pkgdir/usr/share/zbstudio/cfg"

I apologize for thinking it was something wrong with Zerobrane when in fact it's nothing that you are doing.

pkulchenko commented 3 years ago

No problem; thank you for the update. I think I'll keep the patch in, as the original error is still reported (that the file is not accessible), but is no longer fatal.

You may want to report this issue to the maintainers of the install package.