Example_errorCodes demonstrates programmatic error handling
()
| 67 | |
| 68 | // Example_errorCodes demonstrates programmatic error handling |
| 69 | func Example_errorCodes() { |
| 70 | sql := "SELECT * FROM" |
| 71 | location := models.Location{Line: 1, Column: 14} |
| 72 | |
| 73 | // Create an error |
| 74 | err := errors.IncompleteStatementError(location, sql) |
| 75 | |
| 76 | // Check error code programmatically |
| 77 | if errors.IsCode(err, errors.ErrCodeIncompleteStatement) { |
| 78 | fmt.Println("Detected incomplete SQL statement") |
| 79 | } |
| 80 | |
| 81 | // Get error code |
| 82 | code := errors.GetCode(err) |
| 83 | fmt.Printf("Error code: %s\n", code) |
| 84 | |
| 85 | // Output: |
| 86 | // Detected incomplete SQL statement |
| 87 | // Error code: E2005 |
| 88 | } |
| 89 | |
| 90 | // Example_contextExtraction demonstrates SQL context in error messages |
| 91 | func Example_contextExtraction() { |
nothing calls this directly
no test coverage detected