buf icon indicating copy to clipboard operation
buf copied to clipboard

Format abiding very closely with buf.work.yaml conventions

Open bufdev opened this issue 2 years ago • 3 comments

$ buf format -d testdata/format/diff/diff.proto
Failure: input testdata/format/diff/diff.proto was not found - is the directory containing this file defined in your buf.work.yaml?

This is a little annoying, is there anything we can do about this?

bufdev avatar Mar 25 '22 16:03 bufdev

Yea, this has to do with the issue called out here.

This is a problem with buffetch.ProtoFileRef - any of the buf commands that interact with this input type will run into issues like this. For example,

$ buf build private/buf/cmd/buf/testdata/format/diff/diff.proto
Failure: path is empty

In short, we need some better default behavior when a file is not defined with a parent buf.yaml or buf.work.yaml. We probably need to widen the scope of this issue to cover all instances of buffetch.ProtoFileRef - not just the buf format case.

amckinney avatar Mar 28 '22 17:03 amckinney

I run into this issue even when both buf.yaml and buf.work.yaml are provided:

$ gzip -cdq buf-format-workspace.tar.gz | tar xfpv -
$ cd buf-V1PhXJYv/buf/testdata/buf/testdata/proto/image
$ buf format --diff testdata.proto 
Failure: input testdata.proto was not found - is the directory containing this file defined in your buf.work.yaml?
$ cd ../../../..
$ buf format --diff buf/testdata/proto/image/testdata.proto 
Failure: input buf/testdata/proto/image/testdata.proto was not found - is the directory containing this file defined in your buf.work.yaml?

I've noticed that if I remove the bazel-grail directories from the list of directories in buf.work.yaml, things work fine.

buf-format-workspace.tar.gz

noel-yap avatar Jun 02 '22 01:06 noel-yap

@noel-yap your setup is a little broken - you've actually defined a buf.yaml in the same directory as your buf.work.yaml. You should actually rearrange things so that the buf.work.yaml points to directories that (optionally) define a buf.yaml (i.e. buf/testdata/buf.yaml) so that import statements are resolved as expected. For more information on workspaces, please read the documentation.

Everything works as expected after I move the buf.yaml to buf/testdata/buf.yaml:

$ buf format --diff testdata.proto 
diff -u testdata.proto.orig testdata.proto
--- testdata.proto.orig	2022-08-15 09:17:39.000000000 -0700
+++ testdata.proto	2022-08-15 09:17:39.000000000 -0700
@@ -8,10 +8,10 @@
 
 option go_package = "grail.com/buf/testdata/proto/image";
 option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_swagger) = {
-info: {
-title: "Test Data";
-version: "1.0.0";
-};
+  info: {
+    title: "Test Data";
+    version: "1.0.0";
+  };
 };
...

There's still a problem here that we need to address, but that will help you get going w.r.t your issue in the meantime.

amckinney avatar Aug 15 '22 16:08 amckinney