Skip to content

Confusing error message if rules_proto isn't loaded #1080

@phst

Description

@phst

🐞 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Can Close?Will close in 30 days if there is no new activity

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions