Using `use_extension` with something that isn't an extension crashes bazel
- Dominant language
- Java
- Stars
- 25.8k
- Forks
- 4.6k
- Avg merge
- 2d 20h
- Merged PRs (30d)
- 72
Description
### Description of the bug:
I was trying to move a list of things out of the `MODULE.bazel` file, and created a bzl file with something like `artifacts = ["a", "b", "c"]`, then tried to load that with `use_extension()`, resulting in the crash below. See https://github.com/bazelbuild/rules_android/commit/52d9d55bf9f6559cc6b99009d9d37a431a0179c5 for the repro.
```
FATAL: bazel crashed due to an internal error. Printing stack trace:
java.lang.IllegalArgumentException: Unsupported type: class com.google.devtools.build.lib.bazel.bzlmod.ModuleFileGlobals$ModuleExtensionProxy
at com.google.devtools.build.lib.bazel.bzlmod.AttributeValuesAdapter.serializeObject(AttributeValuesAdapter.java:100)
at com.google.devtools.build.lib.bazel.bzlmod.AttributeValuesAdapter.write(AttributeValuesAdapter.java:53)
at com.google.devtools.build.lib.bazel.bzlmod.AttributeValuesAdapter.write(AttributeValuesAdapter.java:44)
at com.google.devtools.build.lib.bazel.bzlmod.Tag_GsonTypeAdapter.write(Tag_GsonTypeAdapter.java:57)
at com.google.devtools.build.lib.bazel.bzlmod.Tag_GsonTypeAdapter.write(Tag_GsonTypeAdapter.java:12)
at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:69)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(CollectionTypeAdapterFactory.java:97)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(CollectionTypeAdapterFactory.java:61)
at com.google.devtools.build.lib.bazel.bzlmod.DelegateTypeAdapterFactory$1.write(DelegateTypeAdapterFactory.java:128)
at com.google.devtools.build.lib.bazel.bzlmod.ModuleExtensionUsage_GsonTypeAdapter.write(ModuleExtensionUsage_GsonTypeAdapter.java:130)
at com.google.devtools.build.lib.bazel.bzlmod.ModuleExtensionUsage_GsonTypeAdapter.write(ModuleExtensionUsage_GsonTypeAdapter.java:17)
at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:69)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(CollectionTypeAdapterFactory.java:97)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(CollectionTypeAdapterFactory.java:61)
at com.google.devtools.build.lib.bazel.bzlmod.DelegateTypeAdapterFactory$1.write(DelegateTypeAdapterFactory.java:128)
at com.google.devtools.build.lib.bazel.bzlmod.Module_GsonTypeAdapter.write(Module_GsonTypeAdapter.java:115)
at com.google.devtools.build.lib.bazel.bzlmod.Module_GsonTypeAdapter.write(Module_GsonTypeAdapter.java:14)
at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:69)
at com.google.gson.internal.bind.MapTypeAdapterFactory$Adapter.write(MapTypeAdapterFactory.java:239)
at com.google.gson.internal.bind.MapTypeAdapterFactory$Adapter.write(MapTypeAdapterFactory.java:145)
at com.google.devtools.build.lib.bazel.bzlmod.DelegateTypeAdapterFactory$1.write(DelegateTypeAdapterFactory.java:128)
at com.google.devtools.build.lib.bazel.bzlmod.BazelLockFileValue_GsonTypeAdapter.write(BazelLockFileValue_GsonTypeAdapter.java:90)
at com.google.devtools.build.lib.bazel.bzlmod.BazelLockFileValue_GsonTypeAdapter.write(BazelLockFileValue_GsonTypeAdapter.java:13)
at com.google.gson.Gson.toJson(Gson.java:747)
at com.google.gson.Gson.toJson(Gson.java:726)
at com.google.gson.Gson.toJson(Gson.java:681)
at com.google.gson.Gson.toJson(Gson.java:661)
at com.google.devtools.build.lib.bazel.bzlmod.BazelLockFileModule.updateLockfile(BazelLockFileModule.java:239)
at com.google.devtools.build.lib.bazel.bzlmod.BazelLockFileModule.afterCommand(BazelLockFileModule.java:106)
at com.google.devtools.build.lib.runtime.BlazeRuntime.afterCommand(BlazeRuntime.java:654)
at com.google.devtools.build.lib.runtime.BlazeCommandDispatcher.execExclusively(BlazeCommandDispatcher.java:704)
at com.google.devtools.build.lib.runtime.BlazeCommandDispatcher.exec(BlazeCommandDispatcher.java:251)
at com.google.devtools.build.lib.server.GrpcServerImpl.executeCommand(GrpcServerImpl.java:607)
at com.google.devtools.build.lib.server.GrpcServerImpl.lambda$run$1(GrpcServerImpl.java:676)
at io.grpc.Context$1.run(Context.java:566)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
```
### Which category does this issue belong to?
External Dependency
### What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
https://github.com/bazelbuild/rules_android/commit/52d9d55bf9f6559cc6b99009d9d37a431a0179c5
### Which operating system are you running Bazel on?
_No response_
### What is the output of `bazel info release`?
_No response_
### If `bazel info release` returns `development version` or `(@non-git)`, tell us how you built Bazel.
_No response_
### What's the output of `git remote get-url origin; git rev-parse HEAD` ?
_No response_
### Is this a regression? If yes, please try to identify the Bazel commit where the bug was introduced.
_No response_
### Have you found anything relevant by searching the web?
_No response_
### Any other information, logs, or outputs that you want to share?
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.