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

Function Example_chainedErrors

pkg/errors/example_test.go:110–136  ·  view source on GitHub ↗

Example_chainedErrors demonstrates error wrapping

()

Source from the content-addressed store, hash-verified

108
109// Example_chainedErrors demonstrates error wrapping
110func 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
139func Example_customHints() {

Callers

nothing calls this directly

Calls 3

NewErrorFunction · 0.92
WrapErrorFunction · 0.92
UnwrapMethod · 0.45

Tested by

no test coverage detected