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

buf generate: fails on symlinks without proper permissions #265

Closed
adambabik opened this issue Feb 16, 2021 · 6 comments
Closed

buf generate: fails on symlinks without proper permissions #265

adambabik opened this issue Feb 16, 2021 · 6 comments

Comments

@adambabik
Copy link

adambabik commented Feb 16, 2021

I tried to run buf generate with one dependency:

deps:
  - buf.build/beta/googleapis

and a broken symlink in the root project directory.

The command failed on resolving the symlink:

buf generate
buf: downloading buf.build/beta/googleapis:1dc4674e3cb949b388204fa2dc321be7
lstat /root/.cache: permission denied

Where a symlink pointed at: /root/.cache/bazel/path/to/file.

@johanbrandhorst
Copy link
Contributor

johanbrandhorst commented Feb 16, 2021

I saw this error too, I think it may have something to do with how the grpc-gateway uses a docker container to generate the files. buf will look for $BUF_CACHE_DIR and $XDG_CACHE_HOME or otherwise fall back to $HOME/.cache, so if this error happens, it's likely something to do with the local configuration. See

func CacheDirPath(envContainer EnvContainer) (string, error) {
and
c.cacheDirPath = c.getDirPath("CACHE_DIR", app.CacheDirPath)
.

Another note, because running generate inside a container can mess with permissions, you may need to run sudo chown $(whoami): -R . after regenerating files.

@adambabik
Copy link
Author

I found this code and tried to use these envs but with no luck (I tried also with CACHE_DIR):

➜ export XDG_CACHE_HOME=$HOME/.cache
➜ echo $XDG_CACHE_HOME 
/home/adamb/.cache
➜ buf generate     
lstat /root/.cache: permission denied

You are right with the docker and permissions being broken but after I fixed it, it's the same error. I can try to dig into the code of buf to find a code path that does not work if it's hard to reproduce. Like I said above, it works like a charm on macOS.

@johanbrandhorst
Copy link
Contributor

I can't reproduce this error locally anymore, but it would be super helpful if you could keep your environment broken and help us debug what's happening here. I'd add some print statements to the code to see why it's choosing that path and rebuild, if you want I can provide the binaries for you to try?

@adambabik adambabik changed the title buf generate: fails on Ubuntu 20.04 buf generate: fails on symlinks without proper permissions Feb 17, 2021
@adambabik
Copy link
Author

I talked with @johanbrandhorst on Buf's Slack. We found that the root cause was a broken symlink pointing at a directory to which the current user had no permissions. I updated the description.

@johanbrandhorst
Copy link
Contributor

In the next release we're making the error message around this a bit clearer so the user knows to look at the contents of their repository.

@bufdev
Copy link
Member

bufdev commented Feb 23, 2021

An updated error message is included in v0.37.1.

@bufdev bufdev closed this as completed Feb 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants