]> begriffs open source - ai-review/blob - critic/sql-error-handling.md
frama-c
[ai-review] / critic / sql-error-handling.md
1 # SQL Error Handling Critic Framework (ISO/IEC 9075:2023)
2
3 This framework guides the Critic role when evaluating SQL code, stored procedures, and database applications for error handling, robustness, and reliability. This critic focuses on consistent error checking, proper error reporting, resource cleanup, and graceful failure recovery to ensure reliable database operations.
4
5 ## SQL Error Handling Evaluation Areas
6
7 ### 1. Error Detection and Checking
8 **What to Look For:**
9 - Consistent error checking in procedures and triggers
10 - Use of standard SQLSTATE codes for error reporting
11 - Proper handling of constraint violations and transaction failures
12 - Comprehensive error condition detection
13 - Clear error propagation strategies
14
15 **Common Problems:**
16 - Ignoring errors in stored procedures or triggers
17 - Inconsistent error handling patterns
18 - Missing error checking for critical operations
19 - Poor error condition detection
20 - Unclear error propagation strategies
21
22 **Evaluation Questions:**
23 - Are all errors detected and handled consistently?
24 - Are SQLSTATE codes used for error reporting?
25 - Are constraint violations handled gracefully?
26 - Are error conditions detected comprehensively?
27 - Are error propagation strategies clear and consistent?
28
29 ### 2. Error Reporting and Logging
30 **What to Look For:**
31 - Clear and actionable error messages
32 - Proper use of SQLSTATE codes and error information
33 - Comprehensive error logging and audit trails
34 - User-friendly error messages for application users
35 - Detailed error information for debugging and troubleshooting
36
37 **Common Problems:**
38 - Unclear or inconsistent error messages
39 - Missing error information for debugging
40 - Poor error logging and audit trails
41 - Non-actionable error messages
42 - Inadequate error context information
43
44 **Evaluation Questions:**
45 - Are error messages clear and actionable?
46 - Is comprehensive error information provided?
47 - Are errors logged for audit and debugging?
48 - Are user-friendly error messages provided?
49 - Is error context information captured?
50
51 ### 3. Resource Cleanup and Recovery
52 **What to Look For:**
53 - Proper resource cleanup on error paths
54 - Transaction rollback on failure
55 - Cursor and connection cleanup
56 - Memory and temporary object cleanup
57 - Graceful degradation on errors
58
59 **Common Problems:**
60 - Resource leaks or uncommitted transactions on error paths
61 - Missing cursor cleanup
62 - Inadequate memory cleanup
63 - Poor transaction rollback handling
64 - No graceful degradation strategies
65
66 **Evaluation Questions:**
67 - Are transactions rolled back on failure?
68 - Are cursors and connections properly cleaned up?
69 - Is memory and temporary object cleanup performed?
70 - Are resources cleaned up on all error paths?
71 - Is graceful degradation implemented?
72
73 ### 4. Transaction Error Handling
74 **What to Look For:**
75 - Proper transaction boundary management
76 - Consistent rollback strategies
77 - Error handling within transaction blocks
78 - Proper isolation level handling
79 - Deadlock detection and resolution
80
81 **Common Problems:**
82 - Inconsistent transaction rollback on errors
83 - Poor deadlock handling
84 - Missing error handling within transactions
85 - Inappropriate isolation level usage
86 - Incomplete transaction cleanup
87
88 **Evaluation Questions:**
89 - Are transactions rolled back consistently on errors?
90 - Is deadlock detection and resolution implemented?
91 - Are errors handled properly within transactions?
92 - Are appropriate isolation levels used?
93 - Is transaction cleanup performed correctly?
94
95 ### 5. Application Error Handling
96 **What to Look For:**
97 - Consistent error handling across application layers
98 - Proper error propagation from database to application
99 - User-friendly error presentation
100 - Error recovery and retry mechanisms
101 - Comprehensive error documentation
102
103 **Common Problems:**
104 - Inconsistent error handling across application layers
105 - Poor error propagation from database
106 - Non-user-friendly error presentation
107 - Missing error recovery mechanisms
108 - Inadequate error documentation
109
110 **Evaluation Questions:**
111 - Is error handling consistent across application layers?
112 - Is error information properly propagated from database?
113 - Are errors presented in a user-friendly manner?
114 - Are error recovery and retry mechanisms implemented?
115 - Is error handling comprehensively documented?
116
117 ## ISO/IEC Standards-Specific Criticism Process
118
119 ### Step 1: Error Detection Analysis
120 1. **Check Error Detection**: Are all errors detected and handled?
121 2. **Evaluate Error Checking**: Is error checking implemented consistently?
122 3. **Assess Error Propagation**: Are error propagation strategies clear?
123 4. **Review Error Conditions**: Are error conditions detected comprehensively?
124
125 ### Step 2: Error Reporting Assessment
126 1. **Check Error Messages**: Are error messages clear and actionable?
127 2. **Evaluate Error Information**: Is comprehensive error information provided?
128 3. **Assess Error Logging**: Are errors logged for audit and debugging?
129 4. **Review Error Context**: Is error context information captured?
130
131 ### Step 3: Resource Cleanup Analysis
132 1. **Check Transaction Rollback**: Are transactions rolled back on failure?
133 2. **Evaluate Resource Cleanup**: Are resources cleaned up on error paths?
134 3. **Assess Memory Management**: Is memory and temporary object cleanup performed?
135 4. **Review Graceful Degradation**: Is graceful degradation implemented?
136
137 ### Step 4: Transaction Error Assessment
138 1. **Check Transaction Boundaries**: Are transaction boundaries managed properly?
139 2. **Evaluate Rollback Strategies**: Are rollback strategies consistent?
140 3. **Assess Deadlock Handling**: Is deadlock detection and resolution implemented?
141 4. **Review Isolation Levels**: Are appropriate isolation levels used?
142
143 ### Step 5: Application Error Analysis
144 1. **Check Error Consistency**: Is error handling consistent across layers?
145 2. **Evaluate Error Propagation**: Is error information properly propagated?
146 3. **Assess User Experience**: Are errors presented in a user-friendly manner?
147 4. **Review Error Recovery**: Are error recovery mechanisms implemented?
148
149 ## ISO/IEC Standards-Specific Criticism Guidelines
150
151 ### Focus on Error Handling Robustness
152 **Good Criticism:**
153 - "The error handling in this procedure is incomplete; transaction rollback is missing."
154 - "Error messages are not actionable; specific error codes and context are missing."
155 - "Resource cleanup is not performed on error paths, risking memory leaks."
156 - "Deadlock detection and resolution is not implemented for this critical operation."
157
158 **Poor Criticism:**
159 - "This error handling is poor."
160 - "This could fail."
161 - "This is unreliable."
162
163 ### Emphasize Error Handling Best Practices
164 **Good Criticism:**
165 - "The procedure does not check for constraint violations before proceeding."
166 - "Error messages lack specific SQLSTATE codes needed for proper error handling."
167 - "Transaction rollback is missing in the error path, risking data inconsistency."
168 - "Cursor cleanup is not performed on error, potentially causing resource leaks."
169
170 **Poor Criticism:**
171 - "This error handling is inadequate."
172 - "This might fail."
173 - "This is not robust."
174
175 ## ISO/IEC Standards-Specific Problem Categories
176
177 ### Error Detection Problems
178 - **Unchecked Errors**: Ignoring errors in procedures or triggers
179 - **Inconsistent Handling**: Different error handling patterns in similar contexts
180 - **Missing Error Checks**: Failure to check for common error conditions
181 - **Poor Error Propagation**: Unclear or inconsistent error propagation strategies
182
183 ### Error Reporting Problems
184 - **Unclear Messages**: Error messages that are not actionable or informative
185 - **Missing Context**: Lack of error context information for debugging
186 - **Poor Logging**: Inadequate error logging and audit trails
187 - **Non-User-Friendly**: Error messages not suitable for end users
188
189 ### Resource Cleanup Problems
190 - **Resource Leaks**: Uncommitted transactions or open cursors on error paths
191 - **Missing Cleanup**: Failure to clean up resources on error paths
192 - **Poor Memory Management**: Inadequate memory and temporary object cleanup
193 - **No Graceful Degradation**: Lack of graceful degradation strategies
194
195 ### Transaction Error Problems
196 - **Inconsistent Rollback**: Inconsistent transaction rollback on errors
197 - **Poor Deadlock Handling**: Missing deadlock detection and resolution
198 - **Missing Error Handling**: Lack of error handling within transactions
199 - **Inappropriate Isolation**: Wrong isolation levels for error-prone operations
200
201 ### Application Error Problems
202 - **Inconsistent Handling**: Different error handling across application layers
203 - **Poor Propagation**: Inadequate error propagation from database to application
204 - **Non-User-Friendly**: Error presentation not suitable for end users
205 - **Missing Recovery**: Lack of error recovery and retry mechanisms
206
207 ## ISO/IEC Standards-Specific Criticism Templates
208
209 ### For Error Detection Issues
210 ```
211 Error Detection Issue: [Specific error detection problem]
212 Problem: [What makes this error detection inadequate]
213 Impact: [Potential for unhandled errors, inconsistent state, or poor user experience]
214 Evidence: [Specific code examples showing missing error checks]
215 Priority: [Critical/High/Medium/Low]
216 ```
217
218 ### For Error Reporting Issues
219 ```
220 Error Reporting Issue: [Specific error reporting problem]
221 Problem: [What makes this error reporting inadequate]
222 Impact: [Potential for poor debugging, user confusion, or inadequate troubleshooting]
223 Evidence: [Specific error message examples or logging deficiencies]
224 Priority: [High/Medium/Low]
225 ```
226
227 ### For Resource Cleanup Issues
228 ```
229 Resource Cleanup Issue: [Specific resource cleanup problem]
230 Problem: [What makes this resource cleanup inadequate]
231 Impact: [Potential for resource leaks, memory issues, or inconsistent state]
232 Evidence: [Specific code examples showing missing cleanup]
233 Priority: [Critical/High/Medium/Low]
234 ```
235
236 ### For Transaction Error Issues
237 ```
238 Transaction Error Issue: [Specific transaction error problem]
239 Problem: [What makes this transaction error handling inadequate]
240 Impact: [Potential for data inconsistency, deadlocks, or poor performance]
241 Evidence: [Specific transaction code examples]
242 Priority: [Critical/High/Medium/Low]
243 ```
244
245 ### For Application Error Issues
246 ```
247 Application Error Issue: [Specific application error problem]
248 Problem: [What makes this application error handling inadequate]
249 Impact: [Potential for poor user experience, inconsistent behavior, or inadequate recovery]
250 Evidence: [Specific application error handling examples]
251 Priority: [High/Medium/Low]
252 ```
253
254 ## ISO/IEC Standards-Specific Criticism Best Practices
255
256 ### Do's
257 - **Focus on Error Robustness**: Identify specific error handling weaknesses
258 - **Emphasize Resource Management**: Ensure proper cleanup and rollback
259 - **Consider User Experience**: Evaluate error messages and user interaction
260 - **Assess Error Propagation**: Review error handling across application layers
261 - **Document Error Handling**: Clearly document error handling strategies
262
263 ### Don'ts
264 - **Ignore Error Handling**: Don't overlook missing error checks
265 - **Accept Poor Error Messages**: Don't tolerate unclear or non-actionable errors
266 - **Skip Resource Cleanup**: Don't ignore resource cleanup requirements
267 - **Overlook Transaction Errors**: Don't accept poor transaction error handling
268 - **Forget User Experience**: Don't ignore the impact of errors on users
269
270 ## ISO/IEC Standards-Specific Criticism Checklist
271
272 ### Error Detection Assessment
273 - [ ] Are all errors detected and handled consistently?
274 - [ ] Are SQLSTATE codes used for error reporting?
275 - [ ] Are constraint violations handled gracefully?
276 - [ ] Are error conditions detected comprehensively?
277 - [ ] Are error propagation strategies clear and consistent?
278
279 ### Error Reporting Assessment
280 - [ ] Are error messages clear and actionable?
281 - [ ] Is comprehensive error information provided?
282 - [ ] Are errors logged for audit and debugging?
283 - [ ] Are user-friendly error messages provided?
284 - [ ] Is error context information captured?
285
286 ### Resource Cleanup Assessment
287 - [ ] Are transactions rolled back on failure?
288 - [ ] Are cursors and connections properly cleaned up?
289 - [ ] Is memory and temporary object cleanup performed?
290 - [ ] Are resources cleaned up on all error paths?
291 - [ ] Is graceful degradation implemented?
292
293 ### Transaction Error Assessment
294 - [ ] Are transactions rolled back consistently on errors?
295 - [ ] Is deadlock detection and resolution implemented?
296 - [ ] Are errors handled properly within transactions?
297 - [ ] Are appropriate isolation levels used?
298 - [ ] Is transaction cleanup performed correctly?
299
300 ### Application Error Assessment
301 - [ ] Is error handling consistent across application layers?
302 - [ ] Is error information properly propagated from database?
303 - [ ] Are errors presented in a user-friendly manner?
304 - [ ] Are error recovery and retry mechanisms implemented?
305 - [ ] Is error handling comprehensively documented?
306
307 ## ISO/IEC Standards-Specific Evaluation Questions
308
309 ### For Any SQL Code
310 1. **Are all errors detected and handled consistently?**
311 2. **Are SQLSTATE codes used for error reporting?**
312 3. **Are transactions rolled back on failure?**
313 4. **Are error messages clear and actionable?**
314 5. **Are resources cleaned up on all error paths?**
315 6. **Is error handling documented and tested?**
316 7. **Are error conditions detected comprehensively?**
317 8. **Is error propagation clear and consistent?**
318 9. **Are error recovery mechanisms implemented?**
319 10. **Is graceful degradation implemented on errors?**
320
321 ### For Stored Procedures and Triggers
322 1. **Are all inputs validated and parameterized?**
323 2. **Are errors detected, reported, and handled consistently?**
324 3. **Are transactions used to ensure atomicity and consistency?**
325 4. **Are side effects documented and controlled?**
326 5. **Is resource cleanup performed on all code paths?**
327
328 ### For Database Applications
329 1. **Is error handling consistent across application layers?**
330 2. **Is error information properly propagated from database?**
331 3. **Are errors presented in a user-friendly manner?**
332 4. **Are error recovery and retry mechanisms implemented?**
333 5. **Is error handling comprehensively documented?**
334
335 ### For Error Handling and Robustness
336 1. **Are all errors detected and handled consistently?**
337 2. **Are SQLSTATE codes used for error reporting?**
338 3. **Are transactions rolled back on failure?**
339 4. **Are error messages clear and actionable?**
340 5. **Are error conditions documented and tested?**
341
342 ## SQL Error Handling Principles Applied
343
344 ### "Ensure Robust Error Detection"
345 - Detect and handle all errors consistently
346 - Use standard error codes and reporting mechanisms
347 - Implement comprehensive error condition detection
348
349 ### "Provide Clear Error Information"
350 - Deliver clear and actionable error messages
351 - Include comprehensive error context for debugging
352 - Maintain proper error logging and audit trails
353
354 ### "Manage Resources Properly"
355 - Clean up resources on all error paths
356 - Roll back transactions on failure
357 - Implement graceful degradation strategies
358
359 ### "Handle Transactions Reliably"
360 - Manage transaction boundaries properly
361 - Implement consistent rollback strategies
362 - Handle deadlocks and concurrency issues
363
364 ### "Consider User Experience"
365 - Present errors in a user-friendly manner
366 - Implement error recovery and retry mechanisms
367 - Provide comprehensive error documentation