• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

nats-io / nats.js / 14209026827

02 Apr 2025 12:47AM UTC coverage: 84.534% (-0.02%) from 84.558%
14209026827

push

github

web-flow
Fix conditional logic for retry mechanism in jsclient.ts (#254)

Updated the conditional statement to ensure proper grouping and evaluate the timeout and no-responders error check accurately. This fixes a potential issue where retries may not trigger as intended.

Signed-off-by: Alberto Ricart <alberto@synadia.com>

2356 of 3206 branches covered (73.49%)

Branch coverage included in aggregate %.

2 of 2 new or added lines in 1 file covered. (100.0%)

1592 existing lines in 26 files now uncovered.

10161 of 11601 relevant lines covered (87.59%)

767944.26 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

83.5
/core/src/msg.ts
1
/*
2
 * Copyright 2020-2024 The NATS Authors
3
 * Licensed under the Apache License, Version 2.0 (the "License");
4
 * you may not use this file except in compliance with the License.
5
 * You may obtain a copy of the License at
6
 *
7
 * http://www.apache.org/licenses/LICENSE-2.0
8
 *
9
 * Unless required by applicable law or agreed to in writing, software
10
 * distributed under the License is distributed on an "AS IS" BASIS,
11
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
 * See the License for the specific language governing permissions and
13
 * limitations under the License.
14
 */
15
import { MsgHdrsImpl } from "./headers.ts";
55✔
16
import type { MsgArg } from "./parser.ts";
17
import { Empty, TD } from "./encoders.ts";
55✔
18
import type {
19
  Msg,
20
  MsgHdrs,
21
  Payload,
22
  Publisher,
23
  RequestInfo,
24
  ReviverFn,
25
} from "./core.ts";
26

27
export class MsgImpl implements Msg {
55✔
28
  _headers?: MsgHdrs;
54✔
29
  _msg: MsgArg;
396,792✔
30
  _rdata: Uint8Array;
396,792✔
31
  _reply!: string;
396,792✔
32
  _subject!: string;
396,792✔
33
  publisher: Publisher;
54✔
34

35
  constructor(msg: MsgArg, data: Uint8Array, publisher: Publisher) {
54✔
36
    this._msg = msg;
396,792✔
37
    this._rdata = data;
396,792✔
38
    this.publisher = publisher;
396,792✔
39
  }
396,792✔
40

41
  get subject(): string {
54✔
42
    if (this._subject) {
116,709✔
43
      return this._subject;
118,392✔
44
    }
118,392✔
45
    this._subject = TD.decode(this._msg.subject);
246,544✔
46
    return this._subject;
246,544✔
47
  }
129,888✔
48

49
  get reply(): string {
54✔
50
    if (this._reply) {
12,117✔
51
      return this._reply;
30,303✔
52
    }
30,303✔
53
    this._reply = TD.decode(this._msg.reply);
29,276✔
54
    return this._reply;
29,276✔
55
  }
12,527✔
56

57
  get sid(): number {
51✔
58
    return this._msg.sid;
54✔
59
  }
54✔
60

61
  get headers(): MsgHdrs | undefined {
53✔
62
    if (this._msg.hdr > -1 && !this._headers) {
2,972✔
63
      const buf = this._rdata.subarray(0, this._msg.hdr);
3,858✔
64
      this._headers = MsgHdrsImpl.decode(buf);
3,858✔
65
    }
3,858✔
66
    return this._headers;
2,972✔
67
  }
2,972✔
68

69
  get data(): Uint8Array {
54✔
70
    if (!this._rdata) {
×
71
      return new Uint8Array(0);
×
72
    }
×
73
    return this._msg.hdr > -1
210,219,645✔
74
      ? this._rdata.subarray(this._msg.hdr)
210,219,645✔
75
      : this._rdata;
210,219,645✔
76
  }
210,219,645✔
77

78
  // eslint-ignore-next-line @typescript-eslint/no-explicit-any
79
  respond(
52✔
80
    data: Payload = Empty,
52✔
81
    opts?: { headers?: MsgHdrs; reply?: string },
52✔
82
  ): boolean {
52✔
83
    if (this.reply) {
3,842✔
84
      this.publisher.publish(this.reply, data, opts);
4,012✔
85
      return true;
4,012✔
86
    }
4,012!
UNCOV
87
    return false;
213✔
UNCOV
88
  }
208✔
89

90
  size(): number {
51✔
91
    const subj = this._msg.subject.length;
1,052✔
92
    const reply = this._msg.reply?.length || 0;
×
93
    const payloadAndHeaders = this._msg.size === -1 ? 0 : this._msg.size;
×
94
    return subj + reply + payloadAndHeaders;
1,052✔
95
  }
1,052✔
96

97
  json<T = unknown>(reviver?: ReviverFn): T {
53✔
98
    return JSON.parse(this.string(), reviver);
162✔
99
  }
162✔
100

101
  string(): string {
54✔
102
    return TD.decode(this.data);
231✔
103
  }
231✔
104

UNCOV
105
  requestInfo(): RequestInfo | null {
33✔
UNCOV
106
    const v = this.headers?.get("Nats-Request-Info");
34✔
UNCOV
107
    if (v) {
34✔
UNCOV
108
      return JSON.parse(
34✔
UNCOV
109
        v,
34✔
UNCOV
110
        function (this: unknown, key: string, value: unknown): unknown {
34✔
111
          if ((key === "start" || key === "stop") && value !== "") {
×
112
            return new Date(Date.parse(value as string));
×
113
          }
×
UNCOV
114
          return value;
37✔
UNCOV
115
        },
34✔
116
      ) as RequestInfo;
UNCOV
117
    }
34!
118
    return null;
×
119
  }
×
120
}
55✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc