Fault Injection
Unfault’s LSP and VS Code extension can integrate with fault to help you run targeted fault injections against your app while you’re looking at a specific route or function.
The goal is not to build a perfect chaos suite on day one. It’s to answer: “What happens if this upstream is slow, flaky, or down?” while you’re still in the code.
Install the fault CLI
Section titled “Install the fault CLI”Install fault from its GitHub releases or directly:
# macOSbrew install fault-project/tap/fault
# Linux / manual installcurl -Lo fault https://github.com/fault-project/fault/releases/latest/download/fault-linux-x86_64chmod +x fault && mv fault ~/.local/bin/Configure the App Base URL
Section titled “Configure the App Base URL”The VS Code extension needs to know where your app is listening. Set in your VS Code settings:
unfault.fault.baseUrl(default:http://127.0.0.1:8000)
This is the target Unfault maps to the local fault proxy.
Run a Fault Injection from VS Code
Section titled “Run a Fault Injection from VS Code”When your cursor is inside a route handler (or a function reached by one), open the Unfault: Context sidebar and use the Fault Injection panel.
When you click Run:
- Unfault starts a streaming proxy with
fault run --proxy "9090=<baseUrl origin>" .... - Unfault opens a split terminal with a ready-to-edit
curl http://127.0.0.1:9090/<route>command. - The curl command is not executed automatically.
This makes the architecture explicit: your client talks to the fault proxy, and the proxy streams traffic to your app.
Generate Scenario Files
Section titled “Generate Scenario Files”If you want repeatable checks, use the Generate scenario file button in the same panel.
Unfault generates one scenario suite per discovered route and saves it under:
tests/fault/if it exists- otherwise
test/fault/if it exists - otherwise it creates
tests/fault/
Each file contains multiple YAML documents separated by --- (a small suite of scenarios for that route).
To run a scenario file:
fault scenario run --scenario tests/fault/post-payments.yamlRunning Fault Injections
Section titled “Running Fault Injections”Use fault run directly for quick, targeted injections:
# Add 200ms latency for 30 seconds, proxying to your appfault run --proxy "9090=http://127.0.0.1:8000" --latency 200ms --duration 30s
# Simulate a complete blackhole (service unreachable)fault run --proxy "9090=http://127.0.0.1:8000" --blackhole --duration 15sThen drive traffic through the proxy port (9090) to observe how your code handles it.
Troubleshooting
Section titled “Troubleshooting”fault not found
- The VS Code extension will prompt if
faultisn’t installed. - You can also set
unfault.fault.executablePathiffaultis not on yourPATH.
Port 9090 already in use
- The fault proxy binds to
127.0.0.1:9090. - If you rerun with a different template, Unfault stops the previous proxy before starting a new one.