FastAPI Exception Validator for VS Code - A VS Code extension that validates exception declarations in FastAPI endpoints in real-time.
faex-vscode is a VS Code extension that integrates with the faex CLI tool. It detects missing exception declarations while writing FastAPI code and allows you to identify and fix issues directly in the editor.
faex CLI must be installed:
pip install faex- Real-time Diagnostics: Automatic exception declaration validation on file save
- Inline Warnings: Display warnings directly on problematic lines
- Quick Fix: Code actions to automatically add missing exception declarations
- CodeLens: Exception summary displayed above each endpoint
- Direct Exception Detection: Detects
raisestatements within endpoint functions - Transitive Exception Tracking: Tracks exceptions raised in called functions
- Configurable Analysis Depth: Set the depth of function call tracking
- Problems Panel: View all exception declaration issues across the project
- Status Bar: Display validation status for the current file
code --install-extension faex-vscode-0.1.0.vsixgit clone https://github.com/hail-kang/vscode-extension-faex.git
cd vscode-extension-faex
npm install
npm run package
npx @vscode/vsce package
code --install-extension faex-vscode-0.1.0.vsixValidation starts automatically when you open a FastAPI router file and save it.
- Command Palette (
Cmd+Shift+P/Ctrl+Shift+P):faex: Check Current File- Validate the current filefaex: Check Workspace- Validate the entire workspacefaex: Show All Exceptions- Display exception list for all endpoints
On lines with missing exception declarations:
- Click the lightbulb icon or press
Cmd+./Ctrl+. - Select "Add missing exception declaration"
Configure in settings.json:
{
"faex.enable": true,
"faex.faexPath": "faex",
"faex.depth": 3,
"faex.ignore": ["HTTPException", "ValidationError"],
"faex.exclude": ["**/tests/**", "**/test_*.py"],
"faex.validateOnSave": true,
"faex.showCodeLens": true
}| Option | Type | Default | Description |
|---|---|---|---|
faex.enable |
boolean | true |
Enable/disable the extension |
faex.faexPath |
string | "faex" |
Path to faex CLI executable |
faex.depth |
number | 3 |
Maximum depth for function call tracking |
faex.ignore |
string[] | [] |
Exception classes to ignore |
faex.exclude |
string[] | [] |
File patterns to exclude from analysis |
faex.validateOnSave |
boolean | true |
Auto-validate on save |
faex.showCodeLens |
boolean | true |
Show CodeLens above endpoints |
Before (warning displayed):
@router.get(
"/users/{user_id}",
exceptions=[UnauthorizedException], # ⚠️ Missing: NotFoundException
)
async def get_user(user_id: int):
user = await get_user_by_id(user_id)
if not user:
raise NotFoundException() # This exception is not declared
return userAfter (Quick Fix applied):
@router.get(
"/users/{user_id}",
exceptions=[UnauthorizedException, NotFoundException], # ✓ Fixed
)
async def get_user(user_id: int):
user = await get_user_by_id(user_id)
if not user:
raise NotFoundException()
return userfaex-vscode/
├── src/
│ ├── extension.ts # Extension entry point
│ ├── types.ts # Type definitions
│ ├── analyzer/
│ │ ├── cli.ts # faex CLI runner
│ │ ├── analyzer.ts # Analysis coordinator
│ │ └── index.ts # Module exports
│ ├── providers/
│ │ ├── diagnostics.ts # Diagnostics provider
│ │ ├── codeAction.ts # Quick Fix provider
│ │ └── codeLens.ts # CodeLens provider
│ ├── commands/
│ │ └── commands.ts # Command registration
│ └── utils/
│ └── config.ts # Configuration management
├── package.json # Extension manifest
├── tsconfig.json # TypeScript configuration
└── esbuild.mjs # Build configuration
- CLI Runner: Spawns faex CLI process and parses JSON output
- Analyzer: Coordinates CLI calls and caches results
- DiagnosticsProvider: Displays warnings via VS Code Diagnostics API
- CodeActionProvider: Provides Quick Fix functionality
- CodeLensProvider: Shows exception summary above endpoints
- Node.js 18+
- VS Code 1.85+
- faex CLI (
pip install faex)
git clone https://github.com/hail-kang/vscode-extension-faex.git
cd vscode-extension-faex
npm installPress F5 in VS Code to launch the Extension Development Host.
# Development build
npm run compile
# Production build
npm run package
# Create VSIX
npx @vscode/vsce package# Lint
npm run lint
# Format
npm run formatThis extension uses the faex CLI under the hood:
- On file save, the extension runs
faex check <file> --format json - Parses the JSON output containing endpoint and exception information
- Creates VS Code diagnostics for undeclared exceptions
- Provides Quick Fix actions to add missing declarations
| Feature | faex (CLI) | faex-vscode |
|---|---|---|
| Analysis Engine | Python AST | faex CLI (wrapper) |
| Execution | Manual/CI | Real-time on save |
| Output Format | Text/JSON/GitHub | VS Code UI |
| Auto Fix | Not supported | Quick Fix |
| Integration | Terminal | Editor native |
- Project structure setup
- faex CLI integration
- DiagnosticsProvider implementation
- CodeActionProvider (Quick Fix) implementation
- CodeLens implementation
- Configuration options
- HoverProvider for detailed exception info
- Workspace-wide analysis caching
- Test coverage
- VS Code Marketplace deployment
- faex - Python CLI version
MIT License - see LICENSE for details.
Issues and PRs are welcome!