Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use %v for errors and %q for strings #1262

Merged
merged 1 commit into from Apr 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion allocation_test.go
Expand Up @@ -39,7 +39,7 @@ func TestAllocationServeConn(t *testing.T) {
func TestAllocationClient(t *testing.T) {
ln, err := net.Listen("tcp4", "127.0.0.1:0")
if err != nil {
t.Fatalf("cannot listen: %s", err)
t.Fatalf("cannot listen: %v", err)
}
defer ln.Close()

Expand Down
4 changes: 2 additions & 2 deletions args_test.go
Expand Up @@ -237,7 +237,7 @@ func TestArgsWriteTo(t *testing.T) {
var w bytebufferpool.ByteBuffer
n, err := a.WriteTo(&w)
if err != nil {
t.Fatalf("unexpected error: %s", err)
t.Fatalf("unexpected error: %v", err)
}
if n != int64(len(s)) {
t.Fatalf("unexpected n: %d. Expecting %d", n, len(s))
Expand Down Expand Up @@ -594,7 +594,7 @@ func TestArgsDeleteAll(t *testing.T) {
a.Add("q2", "1234")
a.Del("q1")
if a.Len() != 1 || a.Has("q1") {
t.Fatalf("Expected q1 arg to be completely deleted. Current Args: %s", a.String())
t.Fatalf("Expected q1 arg to be completely deleted. Current Args: %q", a.String())
}
}

Expand Down
2 changes: 1 addition & 1 deletion brotli.go
Expand Up @@ -140,7 +140,7 @@ func nonblockingWriteBrotli(ctxv interface{}) {

_, err := zw.Write(ctx.p)
if err != nil {
panic(fmt.Sprintf("BUG: brotli.Writer.Write for len(p)=%d returned unexpected error: %s", len(ctx.p), err))
panic(fmt.Sprintf("BUG: brotli.Writer.Write for len(p)=%d returned unexpected error: %v", len(ctx.p), err))
}

releaseRealBrotliWriter(zw, ctx.level)
Expand Down
10 changes: 5 additions & 5 deletions brotli_test.go
Expand Up @@ -118,7 +118,7 @@ func TestCompressHandlerBrotliLevel(t *testing.T) {
s := ctx.Response.String()
br := bufio.NewReader(bytes.NewBufferString(s))
if err := resp.Read(br); err != nil {
t.Fatalf("unexpected error: %s", err)
t.Fatalf("unexpected error: %v", err)
}
ce := resp.Header.Peek(HeaderContentEncoding)
if string(ce) != "" {
Expand All @@ -138,15 +138,15 @@ func TestCompressHandlerBrotliLevel(t *testing.T) {
s = ctx.Response.String()
br = bufio.NewReader(bytes.NewBufferString(s))
if err := resp.Read(br); err != nil {
t.Fatalf("unexpected error: %s", err)
t.Fatalf("unexpected error: %v", err)
}
ce = resp.Header.Peek(HeaderContentEncoding)
if string(ce) != "gzip" {
t.Fatalf("unexpected Content-Encoding: %q. Expecting %q", ce, "gzip")
}
body, err := resp.BodyGunzip()
if err != nil {
t.Fatalf("unexpected error: %s", err)
t.Fatalf("unexpected error: %v", err)
}
if string(body) != expectedBody {
t.Fatalf("unexpected body %q. Expecting %q", body, expectedBody)
Expand All @@ -161,15 +161,15 @@ func TestCompressHandlerBrotliLevel(t *testing.T) {
s = ctx.Response.String()
br = bufio.NewReader(bytes.NewBufferString(s))
if err := resp.Read(br); err != nil {
t.Fatalf("unexpected error: %s", err)
t.Fatalf("unexpected error: %v", err)
}
ce = resp.Header.Peek(HeaderContentEncoding)
if string(ce) != "br" {
t.Fatalf("unexpected Content-Encoding: %q. Expecting %q", ce, "br")
}
body, err = resp.BodyUnbrotli()
if err != nil {
t.Fatalf("unexpected error: %s", err)
t.Fatalf("unexpected error: %v", err)
}
if string(body) != expectedBody {
t.Fatalf("unexpected body %q. Expecting %q", body, expectedBody)
Expand Down
12 changes: 6 additions & 6 deletions bytesconv_test.go
Expand Up @@ -76,7 +76,7 @@ func testParseIPv4(t *testing.T, ipStr string, isValid bool) {
ip, err := ParseIPv4(nil, []byte(ipStr))
if isValid {
if err != nil {
t.Fatalf("unexpected error when parsing ip %q: %s", ipStr, err)
t.Fatalf("unexpected error when parsing ip %q: %v", ipStr, err)
}
s := string(AppendIPv4(nil, ip))
if s != ipStr {
Expand Down Expand Up @@ -131,10 +131,10 @@ func testWriteHexInt(t *testing.T, n int, expectedS string) {
var w bytebufferpool.ByteBuffer
bw := bufio.NewWriter(&w)
if err := writeHexInt(bw, n); err != nil {
t.Fatalf("unexpected error when writing hex %x: %s", n, err)
t.Fatalf("unexpected error when writing hex %x: %v", n, err)
}
if err := bw.Flush(); err != nil {
t.Fatalf("unexpected error when flushing hex %x: %s", n, err)
t.Fatalf("unexpected error when flushing hex %x: %v", n, err)
}
s := string(w.B)
if s != expectedS {
Expand Down Expand Up @@ -168,7 +168,7 @@ func testReadHexIntSuccess(t *testing.T, s string, expectedN int) {
br := bufio.NewReader(r)
n, err := readHexInt(br)
if err != nil {
t.Fatalf("unexpected error: %s. s=%q", err, s)
t.Fatalf("unexpected error: %v. s=%q", err, s)
}
if n != expectedN {
t.Fatalf("unexpected hex int %d. Expected %d. s=%q", n, expectedN, s)
Expand Down Expand Up @@ -274,7 +274,7 @@ func testParseUfloatError(t *testing.T, s string) {
func testParseUfloatSuccess(t *testing.T, s string, expectedF float64) {
f, err := ParseUfloat([]byte(s))
if err != nil {
t.Fatalf("Unexpected error when parsing %q: %s", s, err)
t.Fatalf("Unexpected error when parsing %q: %v", s, err)
}
delta := f - expectedF
if delta < 0 {
Expand All @@ -298,7 +298,7 @@ func testParseUintError(t *testing.T, s string) {
func testParseUintSuccess(t *testing.T, s string, expectedN int) {
n, err := ParseUint([]byte(s))
if err != nil {
t.Fatalf("Unexpected error when parsing %q: %s", s, err)
t.Fatalf("Unexpected error when parsing %q: %v", s, err)
}
if n != expectedN {
t.Fatalf("Unexpected value %d. Expected %d. num=%q", n, expectedN, s)
Expand Down
10 changes: 5 additions & 5 deletions bytesconv_timing_test.go
Expand Up @@ -18,7 +18,7 @@ func BenchmarkAppendHTMLEscape(b *testing.B) {
for i := 0; i < 10; i++ {
buf = AppendHTMLEscape(buf[:0], sOrig)
if string(buf) != sExpected {
b.Fatalf("unexpected escaped string: %s. Expecting %s", buf, sExpected)
b.Fatalf("unexpected escaped string: %q. Expecting %q", buf, sExpected)
}
}
}
Expand All @@ -34,7 +34,7 @@ func BenchmarkHTMLEscapeString(b *testing.B) {
for i := 0; i < 10; i++ {
s = html.EscapeString(sOrig)
if s != sExpected {
b.Fatalf("unexpected escaped string: %s. Expecting %s", s, sExpected)
b.Fatalf("unexpected escaped string: %q. Expecting %q", s, sExpected)
}
}
}
Expand All @@ -49,7 +49,7 @@ func BenchmarkParseIPv4(b *testing.B) {
for pb.Next() {
ip, err = ParseIPv4(ip, ipStr)
if err != nil {
b.Fatalf("unexpected error: %s", err)
b.Fatalf("unexpected error: %v", err)
}
}
})
Expand Down Expand Up @@ -88,10 +88,10 @@ func BenchmarkParseUint(b *testing.B) {
for pb.Next() {
n, err := ParseUint(buf)
if err != nil {
b.Fatalf("unexpected error: %s", err)
b.Fatalf("unexpected error: %v", err)
}
if n != 1234567 {
b.Fatalf("unexpected result: %d. Expecting %s", n, buf)
b.Fatalf("unexpected result: %d. Expecting %q", n, buf)
}
}
})
Expand Down
2 changes: 1 addition & 1 deletion client.go
Expand Up @@ -2630,7 +2630,7 @@ func (c *pipelineConnClient) init() {
// Keep restarting the worker if it fails (connection errors for example).
for {
if err := c.worker(); err != nil {
c.logger().Printf("error in PipelineClient(%q): %s", c.Addr, err)
c.logger().Printf("error in PipelineClient(%q): %v", c.Addr, err)
if netErr, ok := err.(net.Error); ok && netErr.Timeout() {
// Throttle client reconnections on timeout errors
time.Sleep(time.Second)
Expand Down
4 changes: 2 additions & 2 deletions client_example_test.go
Expand Up @@ -16,7 +16,7 @@ func ExampleHostClient() {
// Fetch google page via local proxy.
statusCode, body, err := c.Get(nil, "http://google.com/foo/bar")
if err != nil {
log.Fatalf("Error when loading google page through local proxy: %s", err)
log.Fatalf("Error when loading google page through local proxy: %v", err)
}
if statusCode != fasthttp.StatusOK {
log.Fatalf("Unexpected status code: %d. Expecting %d", statusCode, fasthttp.StatusOK)
Expand All @@ -26,7 +26,7 @@ func ExampleHostClient() {
// Fetch foobar page via local proxy. Reuse body buffer.
statusCode, body, err = c.Get(body, "http://foobar.com/google/com")
if err != nil {
log.Fatalf("Error when loading foobar page through local proxy: %s", err)
log.Fatalf("Error when loading foobar page through local proxy: %v", err)
}
if statusCode != fasthttp.StatusOK {
log.Fatalf("Unexpected status code: %d. Expecting %d", statusCode, fasthttp.StatusOK)
Expand Down