Browse Source

Fix infinite recursion in ErrCode.Error method.

Fixes #9
Brad Fitzpatrick 11 years ago
parent
commit
4ea2134aa5
2 changed files with 27 additions and 1 deletions
  1. 1 1
      errors.go
  2. 26 0
      errors_test.go

+ 1 - 1
errors.go

@@ -46,7 +46,7 @@ func (e ErrCode) String() string {
 	if s, ok := errCodeName[e]; ok {
 	if s, ok := errCodeName[e]; ok {
 		return s
 		return s
 	}
 	}
-	return fmt.Sprintf("unknown error code 0x%x", e)
+	return fmt.Sprintf("unknown error code 0x%x", uint32(e))
 }
 }
 
 
 // ConnectionError is an error that results in the termination of the
 // ConnectionError is an error that results in the termination of the

+ 26 - 0
errors_test.go

@@ -0,0 +1,26 @@
+// Copyright 2014 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+// See https://code.google.com/p/go/source/browse/CONTRIBUTORS
+// Licensed under the same terms as Go itself:
+// https://code.google.com/p/go/source/browse/LICENSE
+
+package http2
+
+import "testing"
+
+func TestErrCodeString(t *testing.T) {
+	tests := []struct {
+		err  ErrCode
+		want string
+	}{
+		{ErrCodeProtocol, "PROTOCOL_ERROR"},
+		{0xf, "unknown error code 0xf"},
+	}
+	for i, tt := range tests {
+		got := tt.err.String()
+		if got != tt.want {
+			t.Errorf("%i. Error = %q; want %q", i, got, tt.want)
+		}
+	}
+}