bc-code-intelligence-mcp
Version:
BC Code Intelligence MCP Server - Complete Specialist Bundle with AI-driven expert consultation, seamless handoffs, and context-preserving workflows
80 lines (58 loc) • 4.24 kB
Markdown
title: "Table Safety Validation Patterns for Error Prevention"
domain: "quinn-tester"
difficulty: "intermediate"
bc_versions: "14+"
tags: ["error-prevention", "table-safety", "validation", "defensive-programming", "data-protection"]
prerequisites: ["error-handling", "al-tables"]
samples: "samples/table-safety-validation-patterns.md"
# Table Safety Validation Patterns for Error Prevention
## Overview
Table safety validation patterns provide defensive programming approaches that prevent common data manipulation errors by validating table state, operation context, and business constraints before executing potentially destructive operations.
**Prevention Strategy**: Implement validation barriers that catch dangerous operations before they can cause data corruption, performance issues, or business logic violations.
## Strategic Framework
### Proactive Error Prevention
- **Validation gates**: Check conditions that could lead to errors before execution
- **Safe defaults**: Design operations to fail safely when validation is incomplete
- **Context awareness**: Validate operations against current business and technical context
- **Recovery preparation**: Include error recovery information in validation failures
### Risk Assessment Strategy
- **Impact evaluation**: Assess potential damage from failed validations
- **Probability analysis**: Focus validation on most likely error scenarios
- **Cost-benefit balance**: Optimize validation overhead against error prevention value
- **Monitoring integration**: Track validation patterns to improve error prevention
## Architecture Patterns
### Multi-Layer Validation Architecture
Implement validation at multiple levels (table, operation, business rule) to create comprehensive error prevention coverage without excessive performance overhead.
### Fail-Fast Pattern Implementation
Design validation to detect and report errors as early as possible in operation execution, minimizing resource waste and simplifying error recovery.
### Contextual Safety Checks
Build validation that considers current operational context, user permissions, data state, and business rules to prevent context-inappropriate operations.
## Implementation Guidelines
### Validation Design Principles
- **Specific error identification**: Provide precise information about validation failures
- **Performance optimization**: Design efficient validation that doesn't significantly impact operation speed
- **Maintainable validation**: Create validation rules that are easy to update as requirements change
- **Comprehensive coverage**: Address common error scenarios systematically
### Error Prevention Strategy
Implement validation patterns that catch errors before they propagate through the system, focusing on operations that could cause data integrity issues or performance problems.
### Recovery Planning Integration
Design validation failures to include guidance for correcting the conditions that caused the validation to fail.
## Best Practices
### Defensive Programming Approach
- **Assume input variability**: Validate all external inputs and parameters
- **Check preconditions**: Verify system state meets operation requirements
- **Validate postconditions**: Ensure operations completed as expected
- **Monitor edge cases**: Pay special attention to boundary conditions and unusual scenarios
### Systematic Validation Implementation
Apply consistent validation patterns across similar operations, ensuring comprehensive error prevention coverage without creating maintenance overhead.
### Documentation and Communication
Clearly document validation logic and error prevention strategies to help team members understand and maintain safety measures.
## Anti-Patterns
### Avoid These Approaches
- **Validation bypass**: Skipping safety checks for convenience or performance
- **Generic error handling**: Non-specific error messages that don't help diagnosis
- **Late validation**: Checking safety conditions after beginning operations
- **Inconsistent application**: Using validation in some contexts but not others
- **Over-validation**: Excessive checking that significantly impacts performance