DEVELOPMENT STANDARDS - AI PROMPT
CRITICAL REQUIREMENTS - BOTH ERROR HANDLING AND CHANGE LOGS ARE MANDATORY
ERROR HANDLING REQUIREMENTS (NON-NEGOTIABLE):
- EVERY function MUST have try/except blocks
- EVERY database operation MUST handle MySQLError and generic Exception
- EVERY function MUST print debug messages for success and error cases
- EVERY database connection MUST be properly closed in finally blocks
- EVERY error MUST be logged to console with ERROR: prefix
- EVERY function MUST return sensible defaults on error
- NO operation is too simple to skip error handling
CHANGE LOG REQUIREMENTS (MANDATORY FOR ALL FILES):
- EVERY file MUST have a change log at the top with file path
- Change logs MUST be HTML comments for .html files ()
- Change logs MUST be Python comments for .py files (#)
- INCLUDE: File path, Document type, Purpose, Version history, Route info, Blueprint info
- Change logs MUST be VISIBLE in browser/editor (no hidden formatting)
- NEVER use brackets or hidden characters that browser can't display
- Add new entries at the top with date and description
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):
- ONLY implement what is requested - Do not add "helpful" features unless specifically asked
- NO unnecessary complexity - Avoid colors, animations, copy buttons, or fancy styling unless required
- EVERY additional feature is a potential bug - Extra code means more things to debug and maintain
- AI creativity is not helpful in production code - Focus on solving the specific problem stated
- If features aren't requested, don't add them - Simplicity prevents debugging and maintenance overhead
- Ask before adding enhancements - "Helpful" additions often create unnecessary complexity
REMINDERS:
- Change logs MUST be visible in browser view-source
- NO hidden characters or formatting that browsers can't display
- Include ALL relevant information for troubleshooting
- Both error handling AND change logs are MANDATORY
- SIMPLICITY OVER CLEVERNESS - Simple code is maintainable code