rules_go icon indicating copy to clipboard operation
rules_go copied to clipboard

misleading error message for missing `protos` attribute on go_proto_library

Open hanwen-flow opened this issue 4 months ago • 3 comments

This was the first time I used go_proto_library in a long time. I had

go_proto_library(
    name = "metrics_go_proto",
        compilers = [
            "@@//lang/rpc:go_proto_compiler",
        ],
    importpath = "xxxx",
    deps = [":metrics_proto"],
)

which is incorrect (should use protos iso. deps). The error message for this is

ERROR: xx/BUILD:5:14: in @@rules_go+//proto:def.bzl%_go_proto_aspect aspect on proto_library rule //xx/proto:metrics_proto: 
Traceback (most recent call last):
	File "/home/hanwen/.cache/bazel/_bazel_hanwen/9456475fcdc74345a14b5217fb53a469/external/rules_go+/proto/def.bzl", line 76, column 26, in _go_proto_aspect_impl
		importpath = attr.importpath,
Error: No attribute 'importpath' in attr. Make sure you declared a rule attribute with this name.
Available attributes: _action_listener, _config_dependencies, _experimental_proto_descriptor_sets_include_source_info, _proto_compiler, _strict_proto_deps, _strict_public_imports, allow_exports, aspect_hints, compatible_with, data, deprecation, deps, exec_compatible_with, exec_properties, expect_failure, exports, features, generator_function, generator_location, generator_name, import_prefix, licenses, name, package_metadata, restricted_to, srcs, strip_import_prefix, tags, target_compatible_with, testonly, toolchains, transitive_configs, visibility

this is confusing, because there is an 'importpath' attribute on go_proto_library.

The docs say that protos is a required attribute. Would it be possible to check this and emit an error message?

hanwen-flow avatar Jul 31 '25 09:07 hanwen-flow

At HEAD the error message has been improved: https://github.com/bazel-contrib/rules_go/blob/55932be4203d0f14f79231a143cfaec0836d53d4/proto/def.bzl#L74

Do you think that's good enough?

fmeum avatar Jul 31 '25 11:07 fmeum

i guess it's better than nothing. I wish it would have simply said "missing required attribute 'protos'".

hanwen-flow avatar Jul 31 '25 11:07 hanwen-flow

Would you be interested in sending a PR? We have access to the rule kind at that point, wonder could make the error message more precise for proto_library.

fmeum avatar Jul 31 '25 12:07 fmeum