dotnet / dotnet/aspnetcore

[Analyzer] Ensure Minimal API Endpoint Returns On All Paths

Open
#37,751 4 comments 13 reactions 1 assignee Claimed by @Youssef1313 View on GitHub
analyzer area-minimal feature-minimal-actions
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 5h
Merged PRs (30d)
276

Description

Given that a Minimal API endpoint uses the `Delegate` or `RequestDelegate` type, it is technically valid that not all paths have return values. While this is valid `C#` code, it likely is not the intent of the developer. Here's an example of a compilable endpoint that results in an unintended result.

![image](https://user-images.githubusercontent.com/228256/138340832-23e71cfc-9d7b-4efb-af95-5a0a3c2f927a.png)

The bug is subtle and could likely cause frustration.

## Solution

Create an analyzer that determines if all paths in an endpoint result in a return value or exception being thrown.

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.