()
| 12 | ) |
| 13 | |
| 14 | func Example_http() { |
| 15 | tp := &http.Transport{Dial: rateLimitDialer} |
| 16 | client := &http.Client{Transport: tp} |
| 17 | ps := &PackageStore{ |
| 18 | client: client, |
| 19 | } |
| 20 | |
| 21 | _, err := ps.Get() |
| 22 | |
| 23 | // Unwrap the HTTP-wrapped error, so we can print a proper stacktrace. |
| 24 | var stErr interface { |
| 25 | error |
| 26 | StackTrace() errors.StackTrace |
| 27 | } |
| 28 | if errors.As(err, &stErr) { |
| 29 | err = stErr |
| 30 | } |
| 31 | |
| 32 | fmt.Printf("Error fetching packages: %s\n", cleanGoRoot(tracetest.MustClean(fmt.Sprintf("%+v", err)))) |
| 33 | // Output: |
| 34 | // Error fetching packages: connect rate limited |
| 35 | // braces.dev/errtrace/benchext.rateLimitDialer |
| 36 | // /path/to/errtrace/benchext/pkgerrors_example_http_test.go:1 |
| 37 | // net/http.(*Transport).dial |
| 38 | // /goroot/src/net/http/transport.go:0 |
| 39 | // net/http.(*Transport).dialConn |
| 40 | // /goroot/src/net/http/transport.go:0 |
| 41 | // net/http.(*Transport).dialConnFor |
| 42 | // /goroot/src/net/http/transport.go:0 |
| 43 | // runtime.goexit |
| 44 | // /goroot/src/runtime/asm_amd64.s:0 |
| 45 | } |
| 46 | |
| 47 | type PackageStore struct { |
| 48 | client *http.Client |
nothing calls this directly
no test coverage detected