MCPcopy Create free account
hub / github.com/ajitpratap0/GoSQLX / Example_errorRecovery

Function Example_errorRecovery

pkg/errors/examples_test.go:317–338  ·  view source on GitHub ↗

Example_errorRecovery demonstrates how to handle and recover from errors

()

Source from the content-addressed store, hash-verified

315
316// Example_errorRecovery demonstrates how to handle and recover from errors
317func 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
341func Example_batchValidation() {

Callers

nothing calls this directly

Calls 2

ExpectedTokenErrorFunction · 0.92
IsCodeFunction · 0.92

Tested by

no test coverage detected