lua-shell-games
lua-shell-games copied to clipboard
capture(): wrap io.(p)open calls in an assert
These operations might fail unnoticed, and then show a very unhelpful error message about handle being nil at the line below.
By wrapping these calls in an assert, we actually get an error where it happens, and can see the error message.
@flokli: Thanks for bringing this up! Can you provide any specific examples of how to trigger these failures? I definitely see that io.(p)open may fail and return an error that we should be handling, but I'm just trying to figure out if there's a simple way to trigger this case so we could add test coverage for this. A test case would also help ensure that we're handling the error in the same fashion across the different versions of Lua/LuaJIT/OpenResty, since there are some funky differences in handling all those in the same fashion.
I stumbled into this while packaging this inside a container that had no bin/sh. Which is clearly suboptimal when executing shell commands ;-) - But the current error message was super misleading.
I'm not sure how to properly provoke this in a test case, but asserting success on operations that can fail sounds like a good idea in any case.
Actually, if Lua doesn't fall back to /bin/sh by default, you might be able to provoke this by setting the SHELL environment variable to some non-existent path.
@GUI did you have a chance reproducing this?