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

An error occurs when the SVN is used #51

Closed
renzijing opened this issue Mar 2, 2022 · 19 comments · Fixed by #60
Closed

An error occurs when the SVN is used #51

renzijing opened this issue Mar 2, 2022 · 19 comments · Fixed by #60
Assignees
Labels
bug Something isn't working

Comments

@renzijing
Copy link

renzijing commented Mar 2, 2022

Call luacheck on the SVN pre-commit, for example, luacheck -v, error when commit code,

"Critical error: Luacheck 0.25.0 bug (please report at
 https://github.com/luarocks/luacheck/issues):
/usr/local/share/lua/5.3/luacheck/main.lua:212: bad argument #1 to 'format' (no
 value)
stack traceback:
	/usr/local/share/lua/5.3/luacheck/utils.lua:187: in function
 </usr/local/share/lua/5.3/luacheck/utils.lua:183>
	[C]: in function 'string.format'
	/usr/local/share/lua/5.3/luacheck/main.lua:212: in upvalue 'get_parser'
	/usr/local/share/lua/5.3/luacheck/main.lua:261: in function
 </usr/local/share/lua/5.3/luacheck/main.lua:260>
	(...tail calls...)
	[C]: in function 'xpcall'
	/usr/local/share/lua/5.3/luacheck/utils.lua:201: in function
 'luacheck.utils.try'
	/usr/local/share/lua/5.3/luacheck/main.lua:343: in main chunk
	[C]: in function 'require'
	...al/lib/luarocks/rocks-5.3/luacheck/0.25.0-1/bin/luacheck:2: in main
 chunk
	[C]: in ?"
@alerque
Copy link
Member

alerque commented Mar 2, 2022

What OS are you on and which version of Lua is involved here? It looks to me like something didn't get installed right. How did you install Luacheck? Are you able to run it on projects without SVN involved or not from a pre-commit hook?

@renzijing
Copy link
Author

renzijing commented Mar 2, 2022

os:centos7
lua:5.3
luarocks is used to install luacheck
It can be called normally in Python on my system
It could be that some things aren't installed properly. I'm new to Linux

@renzijing
Copy link
Author

renzijing commented Mar 3, 2022 via email

@alerque
Copy link
Member

alerque commented Mar 3, 2022

I can look into whether --no-cache is working.

In the mean time, at least one of $XDG_CACHE_HAME or $HOME needs to be set in the run time environment, yes. Being on a Linux system without a $HOME environment variable set is pretty rare, you might want to look into why that is happening because luacheck won't be the only thing that assumes it.

@renzijing
Copy link
Author

I have evn #HOME, this issue only appear in my svn pre-commit hook, Otherwise it's normal, like shell

@alerque
Copy link
Member

alerque commented Mar 7, 2022

Are you by any chance using @pre-commit? This might be a duplicate of #52 and completely miss-diagnosed here. If you have $HOME set you shouldn't need $XDG_CACHE_HOME. It's possible if there is a race condition (as yet unconfirmed) you could just be seeing that.

@alerque
Copy link
Member

alerque commented Mar 23, 2022

I can't make heads or tails of this. It doesn't seem to be an exactly duplicate of #52 (which will be patched soon an included in 0.26.0). Perhaps @asottile can answer if there is there any chance pre-commit is calling --cache with no argument (or an empty string). Could that be happening only for SVN projects? Or if a user miss-configures something?

@asottile
Copy link

@pre-commit doesn't at the moment support svn so that being the cause is a little unlikely

@renzijing
Copy link
Author

only for SVN projects

@alerque
Copy link
Member

alerque commented Mar 25, 2022

Please confirm the function of luacheck outside of your SVN hook script. Just run luacheck . from your project root and report how that does.

@renzijing
Copy link
Author

I've been using it lately. All other invocation methods are fine except SVN hook

@alerque
Copy link
Member

alerque commented Mar 25, 2022

Okay I've confirmed what is going on. Even if --cache is not used, it tries to set a default value before --no-cache is evaluated. The stripped down environment SVN is providing you is the issue. For now I suggest a workaround like this:

HOME=/tmp luacheck --no-cache .

I'll see if there is a way to not try to even guess a default cache location unless it is going to be used.

@alerque alerque added the bug Something isn't working label Mar 25, 2022
@alerque alerque self-assigned this Mar 25, 2022
@renzijing
Copy link
Author

renzijing commented Mar 25, 2022

I might have a problem with what I said earlier, now I'm using the command
'export XDG_CACHE_HOME="/var/cache/luacheck luacheck xxxxx'
it works
but I using the command
'luacheck xxxxx'
it can not work

@alerque
Copy link
Member

alerque commented Mar 25, 2022

The syntax / quoting of that export is entirely wrong. Also if you just want to set a variable for one command you don't need export at all. Try one of these:

XDG_CACHE_HOME=/var/cache/luacheck luacheck xxxxx
# or
luacheck --cache /var/cache/luacheck xxxxx
# or for no cache at all
HOME=/tmp luacheck --no-cache xxxxx

@renzijing
Copy link
Author

I tested it. No
code:
image
Sorry, don't know how to copy the text

@alerque
Copy link
Member

alerque commented Mar 25, 2022

You're doing something completely different. Of course you do need to export if you're running a chain of commands (as && does), but you are not invoking luacheck directly here at all. Depending on what is in ./CheckLuaCode there might be different solutions. What you have should work fine. You could even tell it your cache was in your LuaTempDir directory. The next luacheck release will have a little more flexibility here to use --no-cache even when those env vars are not found (see #60).

@renzijing
Copy link
Author

The release version didn't work at the beginning, I changed it to the code version, but I found the same problem after changing the code version

@alerque
Copy link
Member

alerque commented Mar 25, 2022

I'm sorry I don't understand what you mean at all. Did you try building your own Luacheck from the code in PR 60?

With the current release version, you must specify one of HOME or XDG_CACHE_HOME variables in your environment even if you use --no-cache. It does work if you have one of those specified.

With the version in PR 60 (which will be in the next release) you will be able to not specify any environment variable (in which case it will default to the current directory) or be able to add --no-cache and have it work no matter what the environment is.

@renzijing
Copy link
Author

I use the current version, not PR 60, export XDG_CACHE_HOME, It can use in svn hook.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

Successfully merging a pull request may close this issue.

3 participants