Split the monolithic .architecture-rules.yaml (1700+ lines) into focused domain-specific files in .architecture-rules/ directory: - _main.yaml: Core config, principles, ignore patterns, severity levels - api.yaml: API endpoint rules (API-001 to API-005) - service.yaml: Service layer rules (SVC-001 to SVC-007) - model.yaml: Model rules (MDL-001 to MDL-004) - exception.yaml: Exception handling rules (EXC-001 to EXC-005) - naming.yaml: Naming convention rules (NAM-001 to NAM-005) - auth.yaml: Auth and multi-tenancy rules (AUTH-*, MT-*) - middleware.yaml: Middleware rules (MDW-001 to MDW-002) - frontend.yaml: Frontend rules (JS-*, TPL-*, FE-*, CSS-*) - language.yaml: Language/i18n rules (LANG-001 to LANG-010) - quality.yaml: Code quality rules (QUAL-001 to QUAL-003) Also creates scripts/validators/ module with base classes for future modular validator extraction. The validate_architecture.py loader now auto-detects and merges split YAML files while maintaining backward compatibility with single file mode. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
67 lines
2.2 KiB
YAML
67 lines
2.2 KiB
YAML
# Architecture Rules - Exception Handling Rules
|
|
# Rules for exception handling across the application
|
|
|
|
exception_rules:
|
|
|
|
- id: "EXC-001"
|
|
name: "Define custom exceptions in exceptions module"
|
|
severity: "warning"
|
|
description: |
|
|
Create domain-specific exceptions in app/exceptions/ for better
|
|
error handling and clarity.
|
|
pattern:
|
|
file_pattern: "app/exceptions/**/*.py"
|
|
encouraged_structure: |
|
|
class VendorError(Exception):
|
|
"""Base exception for vendor-related errors"""
|
|
pass
|
|
|
|
- id: "EXC-002"
|
|
name: "Never use bare except"
|
|
severity: "error"
|
|
description: |
|
|
Always specify exception types. Bare except catches everything including
|
|
KeyboardInterrupt and SystemExit.
|
|
pattern:
|
|
file_pattern: "**/*.py"
|
|
anti_patterns:
|
|
- "except:"
|
|
- "except\\s*:"
|
|
|
|
- id: "EXC-003"
|
|
name: "Log all exceptions with context"
|
|
severity: "warning"
|
|
description: |
|
|
When catching exceptions, log them with context and stack trace.
|
|
pattern:
|
|
file_pattern: "app/services/**/*.py"
|
|
encouraged_patterns:
|
|
- "logger.error"
|
|
- "exc_info=True"
|
|
|
|
- id: "EXC-004"
|
|
name: "Domain exceptions must inherit from WizamartException"
|
|
severity: "error"
|
|
description: |
|
|
All custom domain exceptions must inherit from WizamartException (or its
|
|
subclasses like ResourceNotFoundException, ValidationException, etc.).
|
|
This ensures the global exception handler catches and converts them properly.
|
|
pattern:
|
|
file_pattern: "app/exceptions/**/*.py"
|
|
required_base_class: "WizamartException"
|
|
example_good: |
|
|
class VendorNotFoundException(ResourceNotFoundException):
|
|
def __init__(self, vendor_code: str):
|
|
super().__init__(resource_type="Vendor", identifier=vendor_code)
|
|
|
|
- id: "EXC-005"
|
|
name: "Exception handler must be registered"
|
|
severity: "error"
|
|
description: |
|
|
The global exception handler must be set up in app initialization to
|
|
catch WizamartException and convert to HTTP responses.
|
|
pattern:
|
|
file_pattern: "app/main.py"
|
|
required_patterns:
|
|
- "setup_exception_handlers"
|