rules_python icon indicating copy to clipboard operation
rules_python copied to clipboard

Confusing error message if rules_proto isn't loaded

Open phst opened this issue 2 years ago • 4 comments

🐞 bug report

Affected Rule

The issue is caused by the rule: py_proto_library

Is this a regression?

No

Description

A clear and concise description of the problem...

If rules_proto isn't loaded, using py_proto_library fails with a somewhat confusing error message:

ERROR: Traceback (most recent call last):
	File "[…]/external/rules_python/python/private/proto/py_proto_library.bzl", line 20, column 38, in <toplevel>
		ProtoLangToolchainInfo = proto_common.ProtoLangToolchainInfo
Error: 'proto_common' value has no field or method 'ProtoLangToolchainInfo'

Maybe the error message could be improved slightly, e.g. by checking hasattr(proto_common, 'ProtoLangToolchainInfo').

🔬 Minimal Reproduction

WORKSPACE:

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
    name = "rules_python",
    sha256 = "29a801171f7ca190c543406f9894abf2d483c206e14d6acbd695623662320097",
    strip_prefix = "rules_python-0.18.1",
    url = "https://github.com/bazelbuild/rules_python/releases/download/0.18.1/rules_python-0.18.1.tar.gz",
)

load("@rules_python//python:repositories.bzl", "py_repositories")

py_repositories()

BUILD:

load("@rules_python//python:proto.bzl", "py_proto_library")

py_proto_library(
    name = "test_py_pb2",
    deps = [":test_proto"],
)

proto_library(
    name = "test_proto",
    srcs = ["test.proto"],
)

test.proto:

syntax = "proto3";
message Test {}

🔥 Exception or Error

ERROR: Traceback (most recent call last):
	File "[…]/external/rules_python/python/private/proto/py_proto_library.bzl", line 20, column 38, in <toplevel>
		ProtoLangToolchainInfo = proto_common.ProtoLangToolchainInfo
Error: 'proto_common' value has no field or method 'ProtoLangToolchainInfo'

🌍 Your Environment

Debian GNU/Linux

Output of bazel version:

6.0.0

Rules_python version:

0.18.1

phst avatar Feb 20 '23 17:02 phst

This issue has been automatically marked as stale because it has not had any activity for 180 days. It will be closed if no further activity occurs in 30 days. Collaborators can add an assignee to keep this open indefinitely. Thanks for your contributions to rules_python!

github-actions[bot] avatar Aug 19 '23 22:08 github-actions[bot]

This issue was automatically closed because it went 30 days without a reply since it was labeled "Can Close?"

github-actions[bot] avatar Sep 18 '23 22:09 github-actions[bot]

can a maintainer reopen this issue? this seems to be still valid issue. maybe @alexeagle?

thesayyn avatar Nov 08 '23 17:11 thesayyn

This issue has been automatically marked as stale because it has not had any activity for 180 days. It will be closed if no further activity occurs in 30 days. Collaborators can add an assignee to keep this open indefinitely. Thanks for your contributions to rules_python!

github-actions[bot] avatar May 06 '24 22:05 github-actions[bot]