microsoft / microsoft/aspire

Improve Exception Message for Missing Project Metadata Annotation in ResourceContainerImageBuilder.cs

Open
#11,299 13 comments 0 reactions 0 assignees View on GitHub
area-app-model good first issue
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.