// handleError makes the request to the StackDriver Error Reporting API func handleError(errorsClient *errors.Client, d device) { ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) defer cancel() log.Printf("Sending report for %s (%s)", d.Name, d.Id) errorsClient.Reportf(ctx, nil, "Device is offline: %s (%s)", d.Name, d.Id) }
func TestCatchPanicNilClient(t *testing.T) { buf := new(bytes.Buffer) log.SetOutput(buf) defer func() { recover() body := buf.Bytes() if !strings.Contains(string(body), "divide by zero") { t.Errorf("error report didn't contain recovered value") } if !strings.Contains(string(body), "hello, error") { t.Errorf("error report didn't contain message") } if !strings.Contains(string(body), "errors_test.TestCatchPanicNilClient") { t.Errorf("error report didn't contain recovered value") } }() var c *errors.Client defer c.Catch(ctx, errors.WithMessage("hello, error")) var x int x = x / x }