Example_errorRecovery demonstrates how to handle and recover from errors
()
| 315 | |
| 316 | // Example_errorRecovery demonstrates how to handle and recover from errors |
| 317 | func Example_errorRecovery() { |
| 318 | sql := "SELECT * FORM users" |
| 319 | location := models.Location{Line: 1, Column: 10} |
| 320 | |
| 321 | err := errors.ExpectedTokenError("FROM", "FORM", location, sql) |
| 322 | |
| 323 | // Check if error is recoverable |
| 324 | if errors.IsCode(err, errors.ErrCodeExpectedToken) { |
| 325 | fmt.Println("Detected recoverable syntax error") |
| 326 | fmt.Println("Suggestion: Fix the typo and retry") |
| 327 | |
| 328 | // Use the error's hint for auto-correction |
| 329 | if err.Hint != "" { |
| 330 | fmt.Println("Hint:", err.Hint) |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | // Output: |
| 335 | // Detected recoverable syntax error |
| 336 | // Suggestion: Fix the typo and retry |
| 337 | // Hint: Did you mean 'FROM' instead of 'FORM'? |
| 338 | } |
| 339 | |
| 340 | // Example_batchValidation demonstrates validating multiple SQL statements |
| 341 | func Example_batchValidation() { |
nothing calls this directly
no test coverage detected