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

Surface module description in command outputs and errors when possible #3271

Merged
merged 50 commits into from
Aug 27, 2024

Conversation

oliversun9
Copy link
Contributor

This PR makes module.Description public to surface module description in command outputs and errors when possible.

This PR also adds a check for module description uniqueness in workspace provider, before passing them to the module set builder. This means we correctly return an user error when it's an user error, i.e. the buf.yaml v2 is not well formed.

oliversun9 and others added 30 commits August 21, 2024 17:56
error handling for cmds that expect uniq module paths; add todo

test

workspace test

add comments

update comments

update comment

rearrange

cleanup

update comment
author Oliver Sun <[email protected]> 1723165177 -0400
committer Oliver Sun <[email protected]> 1724277829 -0400

parent 06e3428
author Oliver Sun <[email protected]> 1723165177 -0400
committer Oliver Sun <[email protected]> 1724277651 -0400

add includes

update tests

build all modules underneath the input directory

add newline

fix lint

update test

add comments

fix comment

comment

update comment

fix write buf yaml file

changelog

only allow either includes or excludes

update error message

handle possible duplicate paths

improve bucketID format

update errors

remove todo comment

fix verb and add test

update --exclude-path to allow pointing at a module

clear module targets paths if module is excluded;add some test files

update comment

revert decision that allowed --exclude-path to point at module roots

post merge

new line

update comment

update

update comment

add comment

comment

rename

update comment

remove unused test files
Copy link
Contributor

github-actions bot commented Aug 27, 2024

The latest Buf updates on your PR. Results from workflow Buf CI / buf (pull_request).

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed✅ passedAug 27, 2024, 10:24 PM

@@ -1023,6 +1023,7 @@ func (c *controller) buildTargetImageWithConfigs(
c.logger.Debug(
"building image for target module",
zap.String("moduleOpaqueID", module.OpaqueID()),
zap.String("moduleDescription", module.Description()),
Copy link
Contributor Author

@oliversun9 oliversun9 Aug 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New:

buf lint foo --debug
...
DEBUG	building image for target module	{"moduleOpaqueID": "foo-00001", "moduleDescription": "path: \"foo\", excludes: \"foo/bar\""}
...

We could also just get rid of the opaque ID here, but keeping it for debugging purpose.

_, _ = builder.WriteString(opaqueID)
if i != len(m.OpaqueIDs)-1 {
_, _ = builder.WriteString(` -> `)
_, _ = builder.WriteString("cycle detected in module dependencies:\n")
Copy link
Contributor Author

@oliversun9 oliversun9 Aug 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New:

buf dep graph
Failure: cycle detected in module dependencies:
    path: "foo", excludes: "foo/bar"
 -> path: "foo", includes: "foo/bar/baz"
 -> path: "foo", includes: "foo/bar", excludes: "foo/bar/baz"
 -> path: "foo", excludes: "foo/bar"

@@ -449,7 +457,7 @@ func getV1Beta1ProtoUploadRequestContent(
return nil, syserror.New("expected local Module in getProtoLegacyFederationUploadRequestContent")
}
if module.ModuleFullName() == nil {
return nil, syserror.Newf("expected module name for local module %q", module.OpaqueID())
return nil, syserror.Newf("expected module name for local module %q", module.Description())
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Description vs opaqueID does not really matter for syserrors, but I changed it just in case.

@@ -125,7 +125,7 @@ func getSingleRegistryForContentModules(contentModules []bufmodule.Module) (stri
for _, module := range contentModules {
moduleFullName := module.ModuleFullName()
if moduleFullName == nil {
return "", syserror.Newf("expected module name for %q", module.OpaqueID())
return "", syserror.Newf("expected module name for %q", module.Description())
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Description vs opaqueID does not really matter for syserrors, but I changed it just in case.

@@ -143,5 +143,5 @@ func moduleToString(module bufmodule.Module) string {
}
return moduleFullName.String()
}
return module.OpaqueID()
return module.Description()
Copy link
Contributor Author

@oliversun9 oliversun9 Aug 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New:

buf dep graph
digraph {

  "buf.build/osun/separate" -> "path: &#34;foo&#34;, excludes: &#34;foo/bar&#34;"
  "path: &#34;foo&#34;, excludes: &#34;foo/bar&#34;" -> "path: &#34;foo&#34;, includes: &#34;foo/bar/baz&#34;"
  "path: &#34;foo&#34;, includes: &#34;foo/bar/baz&#34;" -> "path: &#34;foo&#34;, includes: &#34;foo/bar&#34;, excludes: &#34;foo/bar/baz&#34;"

}

This output is escaped. Perhaps we should update the definition of Module.Description not to quote paths.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a breaking change and isn't desirable - definitely revert this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted in 9f854e6

moduleConfig,
)
if _, ok := seenModuleDescriptions[moduleDescription]; ok {
return nil, fmt.Errorf("multiple module configs found with the same description: %q", moduleDescription)
Copy link
Contributor Author

@oliversun9 oliversun9 Aug 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New

buf build
Failure: multiple module configs found with the same description: "path: \"foo\", excludes: \"foo/bar\""

The \" looks a bit awkward, should we update the definition of Module.Description not to quote paths?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

%s yes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Double checking, we want

Failure: ... the same description: "path: foo, excludes: foo/bar"
instead of
Failure: ... the same description: path: "foo", excludes: "foo/bar"
right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the latter, which should come through if you use %s instead of %q

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in b4bc182

slicesext.Map(allDepModuleDescriptions, func(moduleDescription string) string { return " " + moduleDescription }),
"\n",
),
)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Failure: all dependencies for module "buf.build/osun/separate" must be named but these modules are not:
  path: "foo", excludes: "foo/bar"
  path: "foo", includes: "foo/bar", excludes: "foo/bar/baz"
  path: "foo", includes: "foo/bar/baz"

// - proot/foo
// - path: proto
// excludes:
// - proot/foo
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this check happen during bufYAMLFile parsing instead?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's fine for this to happen in this layer, since WorkspaceProvider encapsulates the process of parsing the buf.yaml. I think this logic is pretty straightforward here.

// - proot/foo
// - path: proto
// excludes:
// - proot/foo
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's fine for this to happen in this layer, since WorkspaceProvider encapsulates the process of parsing the buf.yaml. I think this logic is pretty straightforward here.

Base automatically changed from osun/dupath to main August 27, 2024 22:19
@bufdev bufdev merged commit 681874a into main Aug 27, 2024
11 checks passed
@bufdev bufdev deleted the osun/make-description-public branch August 27, 2024 22:26
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

Successfully merging this pull request may close these issues.

3 participants