Skip to content

Commit 1f55822

Browse files
committed
errors - wip
Signed-off-by: Alberto Ricart <[email protected]>
1 parent 54c5dc8 commit 1f55822

File tree

126 files changed

+1886
-1616
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

126 files changed

+1886
-1616
lines changed

.github/workflows/consistency_checks.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
runs-on: ubuntu-latest-4-cores
99
strategy:
1010
matrix:
11-
deno-version: [1.45.x]
11+
deno-version: [2.0.x]
1212
module: [
1313
core,
1414
jetstream,

.github/workflows/core.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
runs-on: ubuntu-latest-4-cores
1515
strategy:
1616
matrix:
17-
deno-version: [1.45.x]
17+
deno-version: [2.0.x]
1818
node-version: [22.x]
1919
permissions:
2020
contents: read

.github/workflows/deno_checks.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
runs-on: ubuntu-latest-4-cores
99
strategy:
1010
matrix:
11-
deno-version: [1.45.x]
11+
deno-version: [2.0.x]
1212
module: [core, jetstream, kv, obj, services, transport-deno]
1313

1414
steps:

.github/workflows/jetstream.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
runs-on: ubuntu-latest-4-cores
1515
strategy:
1616
matrix:
17-
deno-version: [1.45.x]
17+
deno-version: [2.0.x]
1818

1919
steps:
2020
- name: Git Checkout Core

.github/workflows/kv.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
runs-on: ubuntu-latest-4-cores
1515
strategy:
1616
matrix:
17-
deno-version: [1.45.x]
17+
deno-version: [2.0.x]
1818

1919
steps:
2020
- name: Git Checkout Core

.github/workflows/node_checks.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
runs-on: ubuntu-latest-4-cores
99
strategy:
1010
matrix:
11-
deno-version: [1.45.x]
11+
deno-version: [2.0.x]
1212
node-version: [22.x]
1313

1414
steps:

.github/workflows/obj.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
runs-on: ubuntu-latest-4-cores
1515
strategy:
1616
matrix:
17-
deno-version: [1.45.x]
17+
deno-version: [2.0.x]
1818

1919
steps:
2020
- name: Git Checkout Core

.github/workflows/services.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
runs-on: ubuntu-latest-4-cores
1515
strategy:
1616
matrix:
17-
deno-version: [1.45.x]
17+
deno-version: [2.0.x]
1818

1919
steps:
2020
- name: Git Checkout Core

.github/workflows/transport-node-test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
test:
1919
strategy:
2020
matrix:
21-
deno-version: [1.45.x]
21+
deno-version: [2.0.x]
2222
node-version: [22.x]
2323

2424
name: test node transport with local dependencies

TODO.md

+2
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@
99
- headers_only is needed in Consumer
1010

1111
- add a test for next/fetch/consume where message size smaller than availablle
12+
13+
- doc

core/README.md

+31-27
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ is working.
107107

108108
```typescript
109109
// import the connect function from a transport
110-
import { connect } from "jsr:@nats-io/nats-[email protected]4";
110+
import { connect } from "jsr:@nats-io/[email protected]7";
111111

112112
const servers = [
113113
{},
@@ -179,7 +179,7 @@ the server.
179179

180180
```typescript
181181
// import the connect function from a transport
182-
import { connect } from "jsr:@nats-io/nats-[email protected]4";
182+
import { connect } from "jsr:@nats-io/[email protected]7";
183183

184184
// to create a connection to a nats-server:
185185
const nc = await connect({ servers: "demo.nats.io:4222" });
@@ -241,8 +241,8 @@ All subscriptions are independent. If two different subscriptions match a
241241
subject, both will get to process the message:
242242

243243
```typescript
244-
import { connect } from "jsr:@nats-io/nats-[email protected]4";
245-
import type { Subscription } from "jsr:@nats-io/nats-[email protected]4";
244+
import { connect } from "jsr:@nats-io/[email protected]7";
245+
import type { Subscription } from "jsr:@nats-io/[email protected]7";
246246
const nc = await connect({ servers: "demo.nats.io:4222" });
247247

248248
// subscriptions can have wildcard subjects
@@ -418,11 +418,11 @@ independent unit. Note that non-queue subscriptions are also independent of
418418
subscriptions in a queue group.
419419

420420
```typescript
421-
import { connect } from "jsr:@nats-io/nats-[email protected]5";
421+
import { connect } from "jsr:@nats-io/[email protected]7";
422422
import type {
423423
NatsConnection,
424424
Subscription,
425-
} from "jsr:@nats-io/nats-[email protected]4";
425+
} from "jsr:@nats-io/[email protected]7";
426426

427427
async function createService(
428428
name: string,
@@ -541,29 +541,33 @@ If you send a request for which there's no interest, the request will be
541541
immediately rejected:
542542

543543
```typescript
544-
import { connect, ErrorCode } from "jsr:@nats-io/[email protected]";
545-
import type { NatsError } from "jsr:@nats-io/[email protected]";
546-
547-
const nc = await connect(
548-
{
549-
servers: `demo.nats.io`,
550-
},
551-
);
544+
import { connect } from "jsr:@nats-io/[email protected]";
545+
import {
546+
NoRespondersError,
547+
RequestError,
548+
TimeoutError,
549+
} from "jsr:@nats-io/[email protected]";
550+
551+
const nc = await connect({
552+
servers: `demo.nats.io`,
553+
});
552554

553555
try {
554556
const m = await nc.request("hello.world");
555557
console.log(m.data);
556558
} catch (err) {
557-
const nerr = err as NatsError;
558-
switch (nerr.code) {
559-
case ErrorCode.NoResponders:
560-
console.log("no one is listening to 'hello.world'");
561-
break;
562-
case ErrorCode.Timeout:
559+
if (err instanceof RequestError) {
560+
if (err.cause instanceof TimeoutError) {
563561
console.log("someone is listening but didn't respond");
564-
break;
565-
default:
566-
console.log("request failed", err);
562+
} else if (err.cause instanceof NoRespondersError) {
563+
console.log("no one is listening to 'hello.world'");
564+
} else {
565+
console.log(
566+
`failed due to unknown error: ${(err.cause as Error)?.message}`,
567+
);
568+
}
569+
} else {
570+
console.log(`request failed: ${(err as Error).message}`);
567571
}
568572
}
569573

@@ -591,7 +595,7 @@ Setting the `user`/`pass` or `token` options, simply initializes an
591595
```typescript
592596
// if the connection requires authentication, provide `user` and `pass` or
593597
// `token` options in the NatsConnectionOptions
594-
import { connect } from "jsr:@nats-io/nats-[email protected]";
598+
import { connect } from "jsr:@nats-io/[email protected]";
595599

596600
const nc1 = await connect({
597601
servers: "127.0.0.1:4222",
@@ -680,8 +684,8 @@ You can specify several options when creating a subscription:
680684
- `timeout`: how long to wait for the first message
681685
- `queue`: the [queue group](#queue-groups) name the subscriber belongs to
682686
- `callback`: a function with the signature
683-
`(err: NatsError|null, msg: Msg) => void;` that should be used for handling
684-
the message. Subscriptions with callbacks are NOT iterators.
687+
`(err: Error|null, msg: Msg) => void;` that should be used for handling the
688+
message. Subscriptions with callbacks are NOT iterators.
685689

686690
#### Auto Unsubscribe
687691

@@ -701,7 +705,7 @@ const sub = nc.subscribe("hello", { timeout: 1000 });
701705
// handle the messages
702706
}
703707
})().catch((err) => {
704-
if (err.code === ErrorCode.Timeout) {
708+
if (err instanceof TimeoutError) {
705709
console.log(`sub timed out!`);
706710
} else {
707711
console.log(`sub iterator got an error!`);

core/deno.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nats-io/nats-core",
3-
"version": "3.0.0-30",
3+
"version": "3.0.0-31",
44
"exports": {
55
".": "./src/mod.ts",
66
"./internal": "./src/internal_mod.ts"

core/examples/snippets/autounsub.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
*/
1515

1616
// import the connect function from a transport
17-
import { connect } from "jsr:@nats-io/nats-[email protected]5";
18-
import type { Subscription } from "jsr:@nats-io/nats-[email protected]5";
17+
import { connect } from "jsr:@nats-io/[email protected]7";
18+
import type { Subscription } from "jsr:@nats-io/[email protected]7";
1919

2020
// create a connection
2121
const nc = await connect({ servers: "demo.nats.io:4222" });

core/examples/snippets/basics.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*/
1515

1616
// import the connect function from a transport
17-
import { connect } from "jsr:@nats-io/nats-[email protected]5";
17+
import { connect } from "jsr:@nats-io/[email protected]7";
1818

1919
// to create a connection to a nats-server:
2020
const nc = await connect({ servers: "demo.nats.io:4222" });

core/examples/snippets/connect.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*/
1515

1616
// import the connect function from a transport
17-
import { connect } from "jsr:@nats-io/nats-[email protected]5";
17+
import { connect } from "jsr:@nats-io/[email protected]7";
1818

1919
const servers = [
2020
{},

core/examples/snippets/headers.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
Empty,
2020
headers,
2121
nuid,
22-
} from "jsr:@nats-io/nats-[email protected]5";
22+
} from "jsr:@nats-io/[email protected]7";
2323

2424
const nc = await connect(
2525
{

core/examples/snippets/json.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*/
1515

1616
// import the connect function from a transport
17-
import { connect } from "jsr:@nats-io/nats-[email protected]5";
17+
import { connect } from "jsr:@nats-io/[email protected]7";
1818

1919
// to create a connection to a nats-server:
2020
const nc = await connect({ servers: "demo.nats.io:4222" });
@@ -30,7 +30,7 @@ const sub = nc.subscribe("people");
3030
for await (const m of sub) {
3131
// typescript will see this as a Person
3232
const p = m.json<Person>();
33-
console.log(`[${sub.getProcessed()}]: ${p.name}`);
33+
console.log(p);
3434
}
3535
})();
3636

core/examples/snippets/no_responders.ts

+32-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
1-
import { connect, ErrorCode } from "jsr:@nats-io/[email protected]";
2-
import type { NatsError } from "jsr:@nats-io/[email protected]";
1+
/*
2+
* Copyright 2024 Synadia Communications, Inc
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+
16+
import { connect } from "jsr:@nats-io/[email protected]";
17+
import {
18+
NoRespondersError,
19+
RequestError,
20+
TimeoutError,
21+
} from "jsr:@nats-io/[email protected]";
322

423
const nc = await connect(
524
{
@@ -11,16 +30,18 @@ try {
1130
const m = await nc.request("hello.world");
1231
console.log(m.data);
1332
} catch (err) {
14-
const nerr = err as NatsError;
15-
switch (nerr.code) {
16-
case ErrorCode.NoResponders:
17-
console.log("no one is listening to 'hello.world'");
18-
break;
19-
case ErrorCode.Timeout:
33+
if (err instanceof RequestError) {
34+
if (err.cause instanceof TimeoutError) {
2035
console.log("someone is listening but didn't respond");
21-
break;
22-
default:
23-
console.log("request failed", err);
36+
} else if (err.cause instanceof NoRespondersError) {
37+
console.log("no one is listening to 'hello.world'");
38+
} else {
39+
console.log(
40+
`failed due to unknown error: ${(err.cause as Error)?.message}`,
41+
);
42+
}
43+
} else {
44+
console.log(`request failed: ${(err as Error).message}`);
2445
}
2546
}
2647

core/examples/snippets/queuegroups.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
* See the License for the specific language governing permissions and
1313
* limitations under the License.
1414
*/
15-
import { connect } from "jsr:@nats-io/nats-[email protected]5";
15+
import { connect } from "jsr:@nats-io/[email protected]7";
1616
import type {
1717
NatsConnection,
1818
Subscription,
19-
} from "jsr:@nats-io/nats-[email protected]4";
19+
} from "jsr:@nats-io/[email protected]7";
2020

2121
async function createService(
2222
name: string,

core/examples/snippets/service.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
*/
1515

1616
// import the connect function from a transport
17-
import { connect } from "jsr:@nats-io/nats-[email protected]5";
18-
import type { Subscription } from "jsr:@nats-io/nats-[email protected]5";
17+
import { connect } from "jsr:@nats-io/[email protected]7";
18+
import type { Subscription } from "jsr:@nats-io/[email protected]7";
1919

2020
// create a connection
2121
const nc = await connect({ servers: "demo.nats.io" });

core/examples/snippets/service_client.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*/
1515

1616
// import the connect function from a transport
17-
import { connect, Empty } from "jsr:@nats-io/nats-[email protected]5";
17+
import { connect, Empty } from "jsr:@nats-io/[email protected]7";
1818

1919
// create a connection
2020
const nc = await connect({ servers: "demo.nats.io:4222" });

core/examples/snippets/stream.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*/
1515

1616
// import the connect function from a transport
17-
import { connect } from "jsr:@nats-io/nats-[email protected]5";
17+
import { connect } from "jsr:@nats-io/[email protected]7";
1818

1919
// to create a connection to a nats-server:
2020
const nc = await connect({ servers: "demo.nats.io" });

core/examples/snippets/sub_timeout.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*/
1515

1616
// import the connect function from a transport
17-
import { connect, ErrorCode } from "jsr:@nats-io/nats-[email protected]5";
17+
import { connect, TimeoutError } from "jsr:@nats-io/[email protected]7";
1818

1919
// to create a connection to a nats-server:
2020
const nc = await connect({ servers: "demo.nats.io:4222" });
@@ -27,7 +27,7 @@ const sub = nc.subscribe("hello", { timeout: 1000 });
2727
// handle the messages
2828
}
2929
})().catch((err) => {
30-
if (err.code === ErrorCode.Timeout) {
30+
if (err instanceof TimeoutError) {
3131
console.log(`sub timed out!`);
3232
} else {
3333
console.log(`sub iterator got an error!`);

0 commit comments

Comments
 (0)