Repository: nats-io/nats.go
Pull request #1381 (2023-08-28 19:39:53)

[FIXED] typos in comments and error messages
Fixes typos in comments and error message found using codespell.


Patch:
diff --git a/jetstream/README.md b/jetstream/README.md
index cd791b0..bd1be57 100644
--- a/jetstream/README.md
+++ b/jetstream/README.md
@@ -178,7 +178,7 @@ for s := range streams.Info() {
     fmt.Println(s.Config.Name)
 }
 if streams.Err() != nil {
-    fmt.Println("Unexpected error ocurred")
+    fmt.Println("Unexpected error occurred")
 }
 
 // list stream names
@@ -187,7 +187,7 @@ for name := range names.Name() {
     fmt.Println(name)
 }
 if names.Err() != nil {
-    fmt.Println("Unexpected error ocurred")
+    fmt.Println("Unexpected error occurred")
 }
 ```
 
@@ -314,7 +314,7 @@ for cons := range consumers.Info() {
     fmt.Println(cons.Name)
 }
 if consumers.Err() != nil {
-    fmt.Println("Unexpected error ocurred")
+    fmt.Println("Unexpected error occurred")
 }
 
 // list consumer names
@@ -323,7 +323,7 @@ for name := range names.Name() {
     fmt.Println(name)
 }
 if names.Err() != nil {
-    fmt.Println("Unexpected error ocurred")
+    fmt.Println("Unexpected error occurred")
 }
 ```
 
@@ -579,7 +579,7 @@ case err := <-ackF.Err():
     fmt.Println(err)
 }
 
-// similarly to syncronous publish, there is a helper method accepting subject and data
+// similarly to synchronous publish, there is a helper method accepting subject and data
 ackF, err = js.PublishAsync("ORDERS.new", []byte("hello"))
 ```
 
diff --git a/jetstream/consumer.go b/jetstream/consumer.go
index ecd75d3..05e0d6c 100644
--- a/jetstream/consumer.go
+++ b/jetstream/consumer.go
@@ -28,7 +28,7 @@ type (
 	// Consumer contains methods for fetching/processing messages from a stream, as well as fetching consumer info
 	Consumer interface {
 		// Fetch is used to retrieve up to a provided number of messages from a stream.
-		// This method will always send a single request and wait until either all messages are retreived
+		// This method will always send a single request and wait until either all messages are retrieved
 		// or request times out.
 		Fetch(batch int, opts ...FetchOpt) (MessageBatch, error)
 		// FetchBytes is used to retrieve up to a provided bytes from the stream.
diff --git a/jetstream/ordered.go b/jetstream/ordered.go
index 0f5b704..231b413 100644
--- a/jetstream/ordered.go
+++ b/jetstream/ordered.go
@@ -230,7 +230,7 @@ func (s *orderedSubscription) Stop() {
 }
 
 // Fetch is used to retrieve up to a provided number of messages from a stream.
-// This method will always send a single request and wait until either all messages are retreived
+// This method will always send a single request and wait until either all messages are retrieved
 // or context reaches its deadline.
 func (c *orderedConsumer) Fetch(batch int, opts ...FetchOpt) (MessageBatch, error) {
 	if c.consumerType == consumerTypeConsume {
diff --git a/js.go b/js.go
index 8836bbb..05637d5 100644
--- a/js.go
+++ b/js.go
@@ -396,7 +396,7 @@ func DirectGetNext(subject string) JSOpt {
 }
 
 // StreamListFilter is an option that can be used to configure `StreamsInfo()` and `StreamNames()` requests.
-// It allows filtering the retured streams by subject associated with each stream.
+// It allows filtering the returned streams by subject associated with each stream.
 // Wildcards can be used. For example, `StreamListFilter(FOO.*.A) will return
 // all streams which have at least one subject matching the provided pattern (e.g. FOO.TEST.A).
 func StreamListFilter(subject string) JSOpt {
@@ -3362,7 +3362,7 @@ func (p AckPolicy) MarshalJSON() ([]byte, error) {
 	case AckExplicitPolicy:
 		return json.Marshal("explicit")
 	default:
-		return nil, fmt.Errorf("nats: unknown acknowlegement policy %v", p)
+		return nil, fmt.Errorf("nats: unknown acknowledgement policy %v", p)
 	}
 }
 


Test patch:
diff --git a/jetstream/test/message_test.go b/jetstream/test/message_test.go
index c150ba2..b463927 100644
--- a/jetstream/test/message_test.go
+++ b/jetstream/test/message_test.go
@@ -69,7 +69,7 @@ func TestMessageDetails(t *testing.T) {
 		t.Fatalf("unexpected error during fetch: %v", err)
 	}
 	if string(msg.Data()) != "msg" {
-		t.Fatalf("Invalid messge body; want: 'msg'; got: %q", string(msg.Data()))
+		t.Fatalf("Invalid message body; want: 'msg'; got: %q", string(msg.Data()))
 	}
 	metadata, err := msg.Metadata()
 	if err != nil {
diff --git a/jetstream/test/publish_test.go b/jetstream/test/publish_test.go
index c8712b5..80ddc71 100644
--- a/jetstream/test/publish_test.go
+++ b/jetstream/test/publish_test.go
@@ -1149,7 +1149,7 @@ func TestPublishMsgAsync(t *testing.T) {
 						t.Fatalf("Invalid headers on message; want: %v; got: %v", pub.expectedHeaders, pub.msg.Header)
 					}
 					if string(msg.Data) != string(pub.msg.Data) {
-						t.Fatalf("Invaid message in ack; want: %q; got: %q", string(pub.msg.Data), string(msg.Data))
+						t.Fatalf("Invalid message in ack; want: %q; got: %q", string(pub.msg.Data), string(msg.Data))
 					}
 				case err := <-ackFuture.Err():
 					if pub.withAckError == nil {
diff --git a/nats_test.go b/nats_test.go
index 5cee524..69cfb28 100644
--- a/nats_test.go
+++ b/nats_test.go
@@ -2854,7 +2854,7 @@ func TestCustomInboxPrefix(t *testing.T) {
 	for _, p := range []string{"$BOB.", "$BOB.*", "$BOB.>", ">", ".", "", "BOB.*.X", "BOB.>.X"} {
 		err := CustomInboxPrefix(p)(opts)
 		if err == nil {
-			t.Fatalf("Expeted error for %q", p)
+			t.Fatalf("Expected error for %q", p)
 		}
 	}
 
diff --git a/test/conn_test.go b/test/conn_test.go
index 5c0d6fe..777cb6f 100644
--- a/test/conn_test.go
+++ b/test/conn_test.go
@@ -2279,7 +2279,7 @@ func TestReceiveInfoWithEmptyConnectURLs(t *testing.T) {
 				// The processing of PONG in sendConnect() should leave the
 				// rest for the readLoop to process.
 				c.Write([]byte("PONG\r\nINFO {\"server_id\":\"server1\",\"connect_urls\":[\"127.0.0.1:4222\", \"127.0.0.1:4223\", \"127.0.0.1:4224\"]}\r\n"))
-				// Wait for the notication
+				// Wait for the notification
 				<-ch
 				// Close the connection in our side and go back into accept
 				c.Close()
diff --git a/test/drain_test.go b/test/drain_test.go
index cf8f279..4db4bca 100644
--- a/test/drain_test.go
+++ b/test/drain_test.go
@@ -257,7 +257,7 @@ func TestDrainConnection(t *testing.T) {
 	expected := int32(50)
 	sleep := 10 * time.Millisecond
 
-	// Create the listner for responses on "bar"
+	// Create the listener for responses on "bar"
 	_, err = nc2.Subscribe("bar", func(_ *nats.Msg) {
 		r := atomic.AddInt32(&responses, 1)
 		if r == expected {
diff --git a/test/js_test.go b/test/js_test.go
index 421fa0b..335fd17 100644
--- a/test/js_test.go
+++ b/test/js_test.go
@@ -2727,7 +2727,7 @@ func TestAccountInfo(t *testing.T) {
 			}
 
 			if !reflect.DeepEqual(test.expected, info) {
-				t.Fatalf("Accoount info does not match; expected: %v; got: %v", test.expected, info)
+				t.Fatalf("Account info does not match; expected: %v; got: %v", test.expected, info)
 			}
 			_, err = js.AddStream(&nats.StreamConfig{Name: "FOO", MaxBytes: 1024})
 			if err != nil {
@@ -2749,7 +2749,7 @@ func TestAccountInfo(t *testing.T) {
 			}
 
 			if !reflect.DeepEqual(test.expected, info) {
-				t.Fatalf("Accoount info does not match; expected: %v; got: %v", test.expected, info)
+				t.Fatalf("Account info does not match; expected: %v; got: %v", test.expected, info)
 			}
 		})
 	}
@@ -4109,7 +4109,7 @@ func TestJetStreamSubscribe_DeliverPolicy(t *testing.T) {
 		t.Fatalf("Error on next msg: %v", err)
 	}
 	if string(msg.Data) != "bar msg 2" {
-		t.Fatalf("Unexepcted last message: %q", msg.Data)
+		t.Fatalf("Unexpected last message: %q", msg.Data)
 	}
 }
 
@@ -7869,7 +7869,7 @@ func TestJetStreamDomain(t *testing.T) {
 	}
 }
 
-// Test that we properly enfore per subject msg limits.
+// Test that we properly enforce per subject msg limits.
 func TestJetStreamMaxMsgsPerSubject(t *testing.T) {
 	const subjectMax = 5
 	msc := nats.StreamConfig{
diff --git a/test/object_test.go b/test/object_test.go
index 8cb9d98..93e345e 100644
--- a/test/object_test.go
+++ b/test/object_test.go
@@ -79,7 +79,7 @@ func TestObjectBasics(t *testing.T) {
 	status, err := obs.Status()
 	expectOk(t, err)
 	if !status.Sealed() {
-		t.Fatalf("exected sealed status")
+		t.Fatalf("expected sealed status")
 	}
 	if status.Size() == 0 {
 		t.Fatalf("size is 0")