Improve Exception Message for Missing Project Metadata Annotation in ResourceContainerImageBuilder.cs
- Dominant language
- C#
- Stars
- 6.3k
- Forks
- 991
- Avg merge
- 2d 15h
- Merged PRs (30d)
- 196
Description
In `src/Aspire.Hosting/Publishing/ResourceContainerImageBuilder.cs`, the exception message thrown when a project metadata annotation is missing currently references the output variable rather than the resource itself:
```csharp
throw new DistributedApplicationException($"The resource '{projectMetadata}' does not have a project metadata annotation.");
```
Since `projectMetadata` will always be null in this context, the error message may be unclear or misleading.
**Recommendation:**
Update the exception message to reference the resource (e.g., `resource.Name` or a unique resource identifier) rather than the missing annotation output variable. For example:
```csharp
throw new DistributedApplicationException($"The resource '{resource.Name}' does not have a project metadata annotation.");
```
This will make exception messages clearer and easier to diagnose during troubleshooting.
**Reference:**
[ResourceContainerImageBuilder.cs#L254](https://github.com/dotnet/aspire/blob/main/src/Aspire.Hosting/Publishing/ResourceContainerImageBuilder.cs#L254)
Drafted by Copilot.
Contributor guide
Assessment
This issue has not been assessed yet.