Files
markitect-main/markitect/exceptions.py
tegwick 0acde1e840 feat: Complete Issue #5 - Schema Generation Foundation for arc42 Architecture Documentation
CRITICAL MILESTONE: Establish schema-driven architecture foundation that unlocks the entire
pathway to HolyGrailRequirement - intelligent arc42 architecture documentation with AI-supported
plan-actual comparison capabilities.

Major Components Implemented:

🎯 SCHEMA GENERATION SERVICE:
• SchemaGenerator class with sophisticated AST analysis capabilities
• Depth-limited heading extraction for arc42 section-specific schemas
• Comprehensive structural element detection (headings, paragraphs, lists, code blocks, etc.)
• JSON Schema Draft 7 compliant output with proper validation metadata
• Robust error handling with domain-specific exceptions (FileNotFoundError, InvalidDepthError)

🖥️ CLI INTEGRATION:
• generate-schema command with full argument and option support
• Multiple output formats (JSON, YAML) with stdout or file output
• Configurable depth limiting for architectural document analysis
• User-friendly summaries and progress feedback
• Integration with existing CLI framework and error handling patterns

📊 COMPREHENSIVE TESTING:
• 6 comprehensive test scenarios covering core functionality and edge cases
• Perfect integration with architectural test system (71 service layer tests passing)
• Test coverage for schema generation, depth limiting, error handling, and JSON compliance
• Architectural layer L4 (Service) test placement following reverse dependency principles

🏗️ STRATEGIC ARCHITECTURE:
• Leverages existing AST processing infrastructure for maximum efficiency
• Builds on proven markdown-it parsing with intelligent caching
• Seamless integration with existing CLI framework and configuration system
• Foundation for Issues #7 (Schema Validation) and #8 (Validation Errors)

Technical Excellence:
- Full JSON Schema Draft 7 specification compliance for validator compatibility
- Sophisticated AST token analysis with structural pattern recognition
- Configurable depth filtering essential for arc42 template compliance
- Comprehensive metadata extraction for architectural analysis
- Robust exception handling with actionable error messages

Strategic Value:
- 🎯 33% completion of critical path Phase 1 (Schema Foundation)
- 🔑 Unlocks schema validation and error reporting capabilities
- 🏛️ Essential building block for arc42 architectural documentation intelligence
- 🚀 Direct pathway to AI-supported plan-actual comparison capabilities

This implementation transforms MarkiTect from advanced markdown processor toward intelligent
architecture documentation platform, establishing the schema-driven foundation critical for
achieving the HolyGrailRequirement of arc42 compliance with AI intelligence.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-29 14:53:05 +02:00

149 lines
3.6 KiB
Python

"""
Markitect domain-specific exceptions.
This module provides a hierarchy of exceptions for the Markitect markdown processing system.
All exceptions preserve context and support proper exception chaining.
"""
from typing import Optional, Dict, Any
class MarkitectError(Exception):
"""Base exception for all Markitect operations.
Provides enhanced error context and proper exception chaining support.
Args:
message: Human-readable error description
cause: Original exception that caused this error (for chaining)
context: Additional context information as key-value pairs
"""
def __init__(self, message: str, cause: Optional[Exception] = None, context: Optional[Dict[str, Any]] = None):
super().__init__(message)
self.cause = cause
self.context = context or {}
# Automatically chain if cause is provided
if cause:
self.__cause__ = cause
def __str__(self) -> str:
"""Enhanced string representation with context."""
base_message = super().__str__()
if self.context:
context_info = ", ".join(f"{k}={v}" for k, v in self.context.items())
base_message = f"{base_message} [Context: {context_info}]"
return base_message
class DocumentError(MarkitectError):
"""Errors related to document processing and management.
Raised when:
- Document parsing fails
- Document structure is invalid
- Document metadata is corrupt
"""
pass
class ASTError(MarkitectError):
"""Errors related to Abstract Syntax Tree operations.
Raised when:
- AST parsing fails
- AST structure is invalid
- AST transformation fails
"""
pass
class CacheError(MarkitectError):
"""Errors related to cache operations.
Raised when:
- Cache read/write operations fail
- Cache corruption is detected
- Cache invalidation fails
"""
pass
class DatabaseError(MarkitectError):
"""Errors related to database operations.
Raised when:
- Database connection fails
- Query execution fails
- Data integrity violations occur
"""
pass
class SchemaError(MarkitectError):
"""Errors related to schema validation and processing.
Raised when:
- Schema validation fails
- Schema parsing errors occur
- Schema generation fails
"""
pass
class ValidationError(MarkitectError):
"""Errors related to document validation against schemas.
Raised when:
- Document doesn't match schema
- Validation rules are violated
- Required fields are missing
"""
pass
class GraphQLError(MarkitectError):
"""Errors related to GraphQL operations.
Raised when:
- GraphQL query parsing fails
- GraphQL execution errors occur
- GraphQL schema issues are encountered
"""
pass
class ConfigurationError(MarkitectError):
"""Errors related to configuration and setup.
Raised when:
- Configuration files are missing or invalid
- Environment setup is incomplete
- Required settings are not configured
"""
pass
class FileNotFoundError(MarkitectError):
"""Errors when requested files cannot be found.
Raised when:
- Markdown files don't exist at specified paths
- Required resource files are missing
- Cache files cannot be located
"""
pass
class InvalidDepthError(MarkitectError):
"""Errors related to invalid depth parameters.
Raised when:
- Depth parameters are negative or zero
- Depth values exceed reasonable limits
- Depth configuration is invalid
"""
pass