Documentation Index
Fetch the complete documentation index at: https://mintlify.com/visible/cruel/llms.txt
Use this file to discover all available pages before exploring further.
Overview
Thecruel() function is the primary API for wrapping any function with chaos engineering behaviors. It intercepts function calls and randomly injects failures, delays, timeouts, and data corruption based on configurable options.
Signature
Parameters
The function to wrap with chaos injection. Can be any synchronous or asynchronous function.
Configuration object for chaos behaviors.
Probability (0-1) of throwing a
CruelError. Example: 0.1 = 10% failure rate.Fixed delay in milliseconds, or range
[min, max] for random delay.Probability (0-1) of causing the function to hang indefinitely.
Maximum random delay in milliseconds to add on top of
delay.Probability (0-1) of corrupting string responses by replacing a random character.
Additional delay spike in milliseconds, or range for random spike.
Whether chaos injection is enabled for this wrapper. Set to
false to disable.Return Value
Returns a wrapped version of the original function with the same signature. When called, the wrapped function applies chaos behaviors before executing the original function.
Examples
Basic Usage
Testing Timeout Handling
Data Corruption Testing
Preset Methods
cruel provides convenient preset methods for common scenarios:
cruel.fail()
cruel.slow()
cruel.timeout()
cruel.flaky()
cruel.unreliable()
cruel.nightmare()
Specialized Namespaces
cruel.network
Network-specific chaos injection. See Network API for details.cruel.http
HTTP-specific chaos behaviors. See HTTP API for details.cruel.stream
Stream manipulation for testing streaming APIs. See Stream API for details.cruel.ai
AI/LLM-specific chaos injection. See AI API for details.Global Control
cruel.enable()
Enables global chaos injection for all wrapped functions.cruel.disable()
Disables all chaos injection globally.cruel.toggle()
Toggles chaos injection on/off.cruel.isEnabled()
Checks if chaos is currently enabled.Statistics
cruel.stats()
Returns detailed statistics about chaos injection.cruel.resetStats()
Resets all statistics counters.Related Methods
- createCruel() - Create a custom cruel instance with default options
- cruel.wrap() - Fluent API for chaining chaos behaviors
- cruel.compose() - Compose multiple resilience patterns