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

Function Example_errorChaining

pkg/errors/examples_test.go:172–202  ·  view source on GitHub ↗

Example_errorChaining demonstrates wrapping errors

()

Source from the content-addressed store, hash-verified

170
171// Example_errorChaining demonstrates wrapping errors
172func Example_errorChaining() {
173 sql := "SELECT * FROM users"
174 location := models.Location{Line: 1, Column: 1}
175
176 // Create a chain of errors
177 rootErr := errors.NewError(
178 errors.ErrCodeInvalidSyntax,
179 "invalid table reference",
180 location,
181 )
182
183 wrappedErr := errors.WrapError(
184 errors.ErrCodeUnexpectedToken,
185 "parser error while processing SELECT",
186 location,
187 sql,
188 rootErr,
189 )
190
191 fmt.Println("Chained Error:")
192 fmt.Println(wrappedErr.Error())
193 fmt.Println()
194
195 // Can unwrap to get root cause
196 if wrappedErr.Unwrap() != nil {
197 fmt.Println("Root cause available through Unwrap()")
198 }
199
200 // Note: Output includes chained error with context
201 // Root cause available through Unwrap()
202}
203
204// Example_customHintsEnhanced demonstrates adding custom hints to errors
205func Example_customHintsEnhanced() {

Callers

nothing calls this directly

Calls 4

NewErrorFunction · 0.92
WrapErrorFunction · 0.92
ErrorMethod · 0.45
UnwrapMethod · 0.45

Tested by

no test coverage detected