TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/Polly-Contrib/Simmy/llms.txt
Use this file to discover all available pages before exploring further.
InjectException policy is Simmy’s primary tool for fault injection: it intercepts calls made through a Polly policy and randomly throws a configured exception before the underlying code runs. This lets you verify that your retry policies, circuit breakers, and fallback handlers respond correctly to network errors, timeouts, or any other exception type — without waiting for those failures to occur naturally in production.
Factory method
InjectOutcomePolicy instance ready for execution.
Quick start
Define the exception to inject
Create the exception object you want Simmy to throw. Any
Exception subtype works.Build the chaos policy
Use the fluent builder to wire up the fault, injection rate, and enabled flag.An injection rate of
0.05 means Simmy will throw the exception on roughly 5% of calls. .Enabled() hard-codes the policy as always active; you can pass a bool variable instead to toggle it at runtime.Fluent option methods
All three methods below are required when building anInjectException policy.
.Fault(exception)
Provides a fixed exception instance to throw. Simmy re-uses the same object on every injected call.
.InjectionRate(double)
A value between
0.0 and 1.0. The policy randomly injects the fault that proportion of the time..Enabled() / .Enabled(bool)
Activates the monkey policy. Pass
false or a variable to pause injection without removing the policy.Dynamic fault generation with a delegate
Instead of injecting a fixed exception, you can supply aFunc<Context, CancellationToken, Exception> delegate. This lets you vary the exception type or message based on runtime state or the Polly Context attached to the current execution.
Dynamic injection rate and enabled flag
Both.InjectionRate and .EnabledWhen accept delegate overloads, so you can drive chaos settings from an external configuration source at runtime — no redeploy needed.
Async variant
Forasync/await code paths, use MonkeyPolicy.InjectExceptionAsync, which returns an AsyncInjectOutcomePolicy and accepts InjectOutcomeAsyncOptions<Exception>. The fluent builder methods are the same — .Fault(), .InjectionRate(), and .Enabled() — except that the delegate overloads for EnabledWhen and InjectionRate return Task rather than plain values.
Using inside a PolicyWrap
Place the Simmy policy innermost inside aPolicyWrap so that your existing Polly resilience policies — retry, circuit-breaker, fallback — still apply and can handle the injected fault exactly as they would handle a real one.
Simmy chaos policies are designed to sit innermost in a
PolicyWrap. The outer Polly policies see the injected exception as a genuine failure, which is the whole point of chaos testing — your resilience code is exercised against it.Enabling and disabling at runtime
TheEnabled family of options gives you a safe way to keep chaos policies deployed in production without them constantly firing. Set a feature flag, environment variable, or configuration value and pass it through .Enabled(bool) or .EnabledWhen(Func<Context, CancellationToken, bool>).
Reference
See Policy Options for a full reference on all shared fluent option methods, including theContext-driven delegate overloads for InjectionRate and EnabledWhen.