Example_errorCodeProgrammaticHandling demonstrates using error codes for logic
()
| 135 | |
| 136 | // Example_errorCodeProgrammaticHandling demonstrates using error codes for logic |
| 137 | func Example_errorCodeProgrammaticHandling() { |
| 138 | sql := "SELECT * FROM" |
| 139 | location := models.Location{Line: 1, Column: 14} |
| 140 | |
| 141 | err := errors.IncompleteStatementError(location, sql) |
| 142 | |
| 143 | // Check error type programmatically |
| 144 | if errors.IsCode(err, errors.ErrCodeIncompleteStatement) { |
| 145 | fmt.Println("Detected incomplete SQL statement") |
| 146 | fmt.Println("Error code:", errors.GetCode(err)) |
| 147 | fmt.Println("Can suggest adding table name") |
| 148 | } |
| 149 | |
| 150 | // Output: |
| 151 | // Detected incomplete SQL statement |
| 152 | // Error code: E2005 |
| 153 | // Can suggest adding table name |
| 154 | } |
| 155 | |
| 156 | // Example_unexpectedCharacter demonstrates unexpected character in SQL |
| 157 | func Example_unexpectedCharacter() { |
nothing calls this directly
no test coverage detected