Skip to content

Add analyzers that help prevent developer gotchas #1426

@WhitWaldo

Description

@WhitWaldo

Describe the feature

This is intended more as a parent issue to track progress for individual analyzers, but the goal is that we reduce some of the opportunities for developers to inadvertently misconfigure things that we might catch at build time and reduce runtime exceptions. Here's a short and evolving list of opportunities here:

Package Name Description Pull Request Fixes
Dapr.Actors Actor cross-serialization errors Ensure that when developers retain DataContract serialization or opt into JSON-based serialization, they're not inadvertently cross-serializing in a way that breaks the serializers and deserializers for either approach. #1441
Dapr.Actors Actor DI registration Identify actors that are referenced but not registered in DI. #1441
Dapr.Actors Don't use UseHttpsRedirection with actors Warn when using UseHttpsRedirection middleware as this breaks Dapr actor discovery
Dapr.Actors Ensure MapActorsHandlers is in app startup When AddActors is found, validate that MapActorsHandlers is in place #1441
Dapr.Actors Validate named callback method for a timer exists on the actor type. When registering a timer in an actor, one specifies the name of the callback method to invoke. This analyzer confirms that this method name exists on the actor type. #1513
Dapr.Workflows Workflow/activity DI registration Identify workflows and workflow activities that are referenced, but not registered in DI #1440
Dapr.Workflows Prevent DI injection errors Ensure that during startup, those resources that require a app.UseX() have it specified in Program.cs
Dapr.Workflows Validate inputs/outputs in workflows and activities Validate that the input and output types to and from a workflow and workflow activity match on either side of the operation. #1399
Dapr.Workflows Check for common non-deterministic calls from workflows Ensure developers are not using Guid.NewGuid or DateTime.UtcNow or variations within workflows themselves as these are not deterministic. For Guid.NewGuid, a fix could use context.NewGuid() instead and for DateTime.UtcNow it can favor context.CurrentUtcDateTime. For others, it could create an activity that performs the same and replaces the text to invoke that activity. Thanks to @marcduiker for the idea
Dapr.Client (current) / Dapr.PubSub (future) Ensure MapSubscribeHandler is in app startup when programmatic subscriptions are used When programmatic subscriptions are used (e.g. WithTopic or a Topic attribute), validate that MapSubscribeHandler is in place** - thanks to @ngruson for the idea #1448
Dapr.Workflows Do not use Parallel.ForEachAsync within a Workflow as it's non-deterministic and thus not supported Validated while evaluating #1577

There are a great many analyzers and code fix providers in the Azure Functions Durable Extension repository that could be adapted for use in Dapr Workflows as well.

Release Note

RELEASE NOTE: ADD Analyzers to help prevent runtime errors

Metadata

Metadata

Assignees

Projects

Status

In progress

Relationships

None yet

Development

No branches or pull requests

Issue actions