Navbar

DEVELOPMENT STANDARDS - AI PROMPT

CRITICAL REQUIREMENTS - BOTH ERROR HANDLING AND CHANGE LOGS ARE MANDATORY

ERROR HANDLING REQUIREMENTS (NON-NEGOTIABLE):

CHANGE LOG REQUIREMENTS (MANDATORY FOR ALL FILES):

CHANGE LOG TEMPLATE FOR HTML FILES:

CHANGE LOG TEMPLATE FOR PYTHON FILES:

# CHANGE LOG
# File: /full/path/to/file.py
# Document Type: Python Module/Blueprint/Utility
# Purpose: Brief description of what this file does
# Blueprint: name_of_blueprint.py (if applicable)
# Route: /route/path (if applicable)
# Dependencies: List key imports/dependencies
# Version History:
# 2025-05-13 v1.1 - Description of changes made
# 2025-05-05 v1.0 - Initial creation

ERROR HANDLING TEMPLATE - USE THIS PATTERN FOR ALL FUNCTIONS:

def example_function_with_mandatory_error_handling():
    """
    MANDATORY ERROR HANDLING PATTERN
    Copy this pattern for every function in this module
    """
    # 1. Initialize all variables that need cleanup
    conn = None
    cur = None
    
    try:
        # 2. Add debug print at function start
        print(f"DEBUG: function_name - Starting at {datetime.now()}")
        
        # 3. Validate all inputs FIRST
        # if not valid_input:
        #     print(f"ERROR: function_name - Invalid input: {input_value}")
        #     return default_value
        
        # 4. Get database connection
        conn = get_db_connection()
        if not conn:
            print(f"ERROR: function_name - Failed to get database connection")
            return default_value
            
        # 5. Your database operations here
        # cur = conn.cursor(dictionary=True)
        # ... database operations ...
        
        # 6. Success debug message
        print(f"DEBUG: function_name - Operation successful")
        return result
        
    except MySQLError as e:
        # 7. Handle database-specific errors
        print(f"ERROR: function_name - MySQL error: {e}")
        if conn:
            conn.rollback()
        return default_value
        
    except Exception as e:
        # 8. Handle all other errors
        print(f"ERROR: function_name - Unexpected error: {e}")
        print(f"ERROR: function_name - Traceback: {traceback.format_exc()}")
        if conn:
            conn.rollback()
        return default_value
        
    finally:
        # 9. ALWAYS clean up resources
        if cur:
            cur.close()
            print(f"DEBUG: function_name - Database cursor closed")
        if conn:
            conn.close()
            print(f"DEBUG: function_name - Database connection closed")
        print(f"DEBUG: function_name - Function completed at {datetime.now()}")

SIMPLICITY PRINCIPLE (CRITICAL):

REMINDERS: