Example_chainedErrors demonstrates error wrapping
()
| 108 | |
| 109 | // Example_chainedErrors demonstrates error wrapping |
| 110 | func Example_chainedErrors() { |
| 111 | sql := "SELECT * FROM users" |
| 112 | location := models.Location{Line: 1, Column: 1} |
| 113 | |
| 114 | // Create a chain of errors |
| 115 | rootErr := errors.NewError( |
| 116 | errors.ErrCodeInvalidSyntax, |
| 117 | "invalid table reference", |
| 118 | location, |
| 119 | ) |
| 120 | |
| 121 | wrappedErr := errors.WrapError( |
| 122 | errors.ErrCodeUnexpectedToken, |
| 123 | "parser error", |
| 124 | location, |
| 125 | sql, |
| 126 | rootErr, |
| 127 | ) |
| 128 | |
| 129 | // Can unwrap to get root cause |
| 130 | if wrappedErr.Unwrap() == rootErr { |
| 131 | fmt.Println("Successfully wrapped error") |
| 132 | } |
| 133 | |
| 134 | // Output: |
| 135 | // Successfully wrapped error |
| 136 | } |
| 137 | |
| 138 | // Example_customHints demonstrates adding custom hints |
| 139 | func Example_customHints() { |