Eager error checking for 'RUNFILES_DIR' in the run template#900
Eager error checking for 'RUNFILES_DIR' in the run template#900stagnation wants to merge 1 commit intoaspect-build:mainfrom
Conversation
I had a weird error occur during a `--sandbox_debug` session where instead of running the code it just crashed with
```
Error: × Unable to run command:
├─▶ Unable to create base venv directory
╰─▶ Permission denied (os error 13)
```
```
4062937 stat("/.mutator.venv", 0x7fff2b5c0ed0) = -1 ENOENT (No such file or directory)
4062937 mkdir("/.mutator.venv", 0777) = -1 EACCES (Permission denied)
4062937 stat("/.mutator.venv", 0x7fff2b5c0c20) = -1 ENOENT (No such file or directory)
4062937 write(2, "\33[31m \342\224\234\342\224\200\342\226\266 \33[0mUnable to create base venv directory", 57) = 57
```
This came from not having the RUNFILES_DIR environment variable setup correctly. Which could be because bazel's `--show_subcommands` did not print it properly, I don't know precisely why and did not care to chase it down, I might do that later, or chalk it up to user error.
This script does have `set -u` so I expect it to just fail instead of proceeding with an empty variable expansion and bug chasing exercise but with this eager control I now have a more actionable error message.
|
|
|
|
For the reference, here is a redacted I should note that we do not see the hermetic-sandbox "open /bin/sh -i" here |
|
And I don't get all the RUNFILES variables through |
|
Doing some more tinkering in the sandbox I realize that the variable is removed by Gives the (redacted) output: |
|
The runfiles issue was an optimization Here is the trace of the bash runfiles library execution Diagnosed well: With |
|
I updated the PR message :) Do you think I should also file an issue with the upstream runfiles snippet? That it would be better if it explicitly unset the variables? |

I had a weird error occur during a
--sandbox_debugsession where instead of running the code it just crashed withThis came from not having the RUNFILES_DIR environment variable setup correctly. This was with a remote build (did not try to reproduce with a local build) with
--build_runfile_links=falseso the bash runfiles snippet could not find the directories and set the variables to empty values. This is not caught byset -uas they are indeed set.Instead the script proceeds with an empty variable expansion and bug. With this change we get a more actionable error message and avoids running code that targets "<empty>/<something>" which is known to be a bad idea. Thankfully it just crashes but with hard to understand messages. Where the sandbox debug behavior does not reflect what actually happens in the action when run by Bazel.
Changes are visible to end-users: yes/no
Improves error reporting in rare cases. Avoids the risk of follow on errors of empty shell variables.
Test plan
I think the key here is build remotely without runfiles links, then follow Bazel's sandbox debug functionality.