Skip to content

Commit

Permalink
[TS] new version of typescript (deno 2.0) override keyword is required (
Browse files Browse the repository at this point in the history
#70)

[TS] new version of typescript (deno 2.0) have unknown catch.
[CI] ci test flappers

Signed-off-by: Alberto Ricart <[email protected]>
  • Loading branch information
aricart authored Oct 11, 2024
1 parent 8f28c54 commit 48eec73
Show file tree
Hide file tree
Showing 36 changed files with 118 additions and 109 deletions.
4 changes: 2 additions & 2 deletions core/src/codec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ export function JSONCodec<T = unknown>(
}
return TE.encode(JSON.stringify(d));
} catch (err) {
throw NatsError.errorForCode(ErrorCode.BadJson, err);
throw NatsError.errorForCode(ErrorCode.BadJson, err as Error);
}
},

decode(a: Uint8Array): T {
try {
return JSON.parse(TD.decode(a), reviver);
} catch (err) {
throw NatsError.errorForCode(ErrorCode.BadJson, err);
throw NatsError.errorForCode(ErrorCode.BadJson, err as Error);
}
},
};
Expand Down
2 changes: 0 additions & 2 deletions core/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,6 @@ export class Messages {
const messages: Messages = new Messages();

export class NatsError extends Error {
name: string;
message: string;
// TODO: on major version this should change to a number/enum
code: string;
permissionContext?: { operation: string; subject: string; queue?: string };
Expand Down
6 changes: 3 additions & 3 deletions core/src/nats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ export class NatsConnectionImpl implements NatsConnection {
try {
this.publish(subject, data, { reply: sub.getSubject() });
} catch (err) {
cancel(err);
cancel(err as NatsError);
}

let timer = setTimeout(() => {
Expand Down Expand Up @@ -328,7 +328,7 @@ export class NatsConnectionImpl implements NatsConnection {
},
);
} catch (err) {
r.cancel(err);
r.cancel(err as NatsError);
}
}

Expand Down Expand Up @@ -418,7 +418,7 @@ export class NatsConnectionImpl implements NatsConnection {
},
);
} catch (err) {
r.cancel(err);
r.cancel(err as NatsError);
}

const p = Promise.race([r.timer, r.deferred]);
Expand Down
2 changes: 1 addition & 1 deletion core/src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export function parseOptions(opts?: ConnectionOptions): ConnectionOptions {
try {
createInbox(options.inboxPrefix);
} catch (err) {
throw new NatsError(err.message, ErrorCode.ApiError);
throw new NatsError((err as Error).message, ErrorCode.ApiError);
}
}

Expand Down
8 changes: 4 additions & 4 deletions core/src/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ export class ProtocolHandler implements Dispatcher<ParserEvent> {
if (timer) {
timer.cancel();
}
await this.transport.close(err);
await this.transport.close(err as Error);
throw err;
}
}
Expand All @@ -608,7 +608,7 @@ export class ProtocolHandler implements Dispatcher<ParserEvent> {
// if here we connected
return;
} catch (err) {
lastErr = err;
lastErr = err as Error;
}
}
// if we are here, we failed, and we have no additional
Expand Down Expand Up @@ -659,7 +659,7 @@ export class ProtocolHandler implements Dispatcher<ParserEvent> {
await this._doDial(srv);
break;
} catch (err) {
lastError = err;
lastError = err as Error;
if (!this.connectedOnce) {
if (this.options.waitOnFirstConnect) {
continue;
Expand Down Expand Up @@ -839,7 +839,7 @@ export class ProtocolHandler implements Dispatcher<ParserEvent> {
this.transport.send(PING_CMD);
} catch (err) {
// if we are dying here, this is likely some an authenticator blowing up
this._close(err);
this._close(err as Error);
}
}
if (updates) {
Expand Down
6 changes: 3 additions & 3 deletions core/src/typedsub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,15 @@ export class TypedSubscription<T> extends QueuedIteratorImpl<T>
return this.sub.getSubject();
}

getReceived(): number {
override getReceived(): number {
return this.sub.getReceived();
}

getProcessed(): number {
override getProcessed(): number {
return this.sub.getProcessed();
}

getPending(): number {
override getPending(): number {
return this.sub.getPending();
}

Expand Down
6 changes: 3 additions & 3 deletions core/tests/auth_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Deno.test("auth - none", async () => {
await nc.close();
fail("shouldnt have been able to connect");
} catch (ex) {
assertErrorCode(ex, ErrorCode.AuthorizationViolation);
assertErrorCode(ex as NatsError, ErrorCode.AuthorizationViolation);
}
await ns.stop();
});
Expand All @@ -89,7 +89,7 @@ Deno.test("auth - bad", async () => {
await nc.close();
fail("shouldnt have been able to connect");
} catch (ex) {
assertErrorCode(ex, ErrorCode.AuthorizationViolation);
assertErrorCode(ex as NatsError, ErrorCode.AuthorizationViolation);
}
await ns.stop();
});
Expand Down Expand Up @@ -447,7 +447,7 @@ Deno.test("basics - bad auth", async () => {
},
);
} catch (err) {
assertErrorCode(err, ErrorCode.AuthorizationViolation);
assertErrorCode(err as NatsError, ErrorCode.AuthorizationViolation);
}
});

Expand Down
10 changes: 6 additions & 4 deletions core/tests/basics_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ Deno.test("basics - no publish without subject", async () => {
nc.publish("");
fail("should not be able to publish without a subject");
} catch (err) {
assertEquals(err.code, ErrorCode.BadSubject);
assertEquals((err as NatsError).code, ErrorCode.BadSubject);
} finally {
await cleanup(ns, nc);
}
Expand Down Expand Up @@ -723,14 +723,14 @@ Deno.test("basics - no max_payload messages", async () => {
nc.publish(subj, big);
fail();
} catch (err) {
assertErrorCode(err, ErrorCode.MaxPayloadExceeded);
assertErrorCode(err as NatsError, ErrorCode.MaxPayloadExceeded);
}

try {
await nc.request(subj, big).then();
fail();
} catch (err) {
assertErrorCode(err, ErrorCode.MaxPayloadExceeded);
assertErrorCode(err as NatsError, ErrorCode.MaxPayloadExceeded);
}

const sub = nc.subscribe(subj);
Expand Down Expand Up @@ -1238,7 +1238,9 @@ Deno.test("basics - initial connect error", async () => {
// in node we may get a disconnect which we generated
// in deno we get the connection reset - but if running in CI this may turn out to be
// a connection refused
assertArrayIncludes(["ECONNRESET", "CONNECTION_REFUSED"], [err.code]);
assertArrayIncludes(["ECONNRESET", "CONNECTION_REFUSED"], [
(err as NatsError).code,
]);
}
listener.close();
await done;
Expand Down
4 changes: 2 additions & 2 deletions core/tests/drain_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
import { assert, assertEquals, fail } from "jsr:@std/assert";
import { createInbox, ErrorCode, StringCodec } from "../src/internal_mod.ts";
import type { Msg } from "../src/internal_mod.ts";
import type { Msg, NatsError } from "../src/internal_mod.ts";
import {
assertThrowsAsyncErrorCode,
assertThrowsErrorCode,
Expand Down Expand Up @@ -160,7 +160,7 @@ Deno.test("drain - reject reqrep during connection drain", async () => {
fail("shouldn't have been able to request");
lock.unlock();
} catch (err) {
assertEquals(err.code, ErrorCode.ConnectionDraining);
assertEquals((err as NatsError).code, ErrorCode.ConnectionDraining);
lock.unlock();
}
}
Expand Down
2 changes: 1 addition & 1 deletion core/tests/reconnect_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ Deno.test("reconnect - events", async () => {
try {
await nc.closed();
} catch (err) {
assertErrorCode(err, ErrorCode.ConnectionRefused);
assertErrorCode(err as NatsError, ErrorCode.ConnectionRefused);
}
assertEquals(disconnects, 1);
assertEquals(reconnecting, 10);
Expand Down
4 changes: 2 additions & 2 deletions core/tests/timeout_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Deno.test("timeout - request noMux stack is useful", async () => {
await nc.request(subj, Empty, { noMux: true, timeout: 250 });
fail("request should have failed!");
} catch (err) {
assertStringIncludes(err.stack, "timeout_test");
assertStringIncludes((err as Error).stack || "", "timeout_test");
}
await nc.close();
});
Expand All @@ -35,7 +35,7 @@ Deno.test("timeout - request stack is useful", async () => {
await nc.request(subj, Empty, { timeout: 250 });
fail("request should have failed!");
} catch (err) {
assertStringIncludes(err.stack, "timeout_test");
assertStringIncludes((err as Error).stack || "", "timeout_test");
}
await nc.close();
});
4 changes: 2 additions & 2 deletions core/tests/token_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Deno.test("token - empty", async () => {
await nc.close();
fail("should not have connected");
} catch (err) {
assertErrorCode(err, ErrorCode.AuthorizationViolation);
assertErrorCode(err as Error, ErrorCode.AuthorizationViolation);
}
await ns.stop();
});
Expand All @@ -45,7 +45,7 @@ Deno.test("token - bad", async () => {
await nc.close();
fail("should not have connected");
} catch (err) {
assertErrorCode(err, ErrorCode.AuthorizationViolation);
assertErrorCode(err as Error, ErrorCode.AuthorizationViolation);
}
await ns.stop();
});
Expand Down
12 changes: 6 additions & 6 deletions jetstream/src/consumer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ export class PullConsumerMessagesImpl extends QueuedIteratorImpl<JsMsg>
fn();
}
} catch (err) {
this.stop(err);
this.stop(err as Error);
}
}
}
Expand Down Expand Up @@ -493,22 +493,22 @@ export class PullConsumerMessagesImpl extends QueuedIteratorImpl<JsMsg>
return true;
} catch (err) {
// game over
if (err.message === "stream not found") {
if ((err as Error).message === "stream not found") {
streamNotFound++;
this.notify(ConsumerEvents.StreamNotFound, streamNotFound);
if (!this.isConsume || this.abortOnMissingResource) {
this.stop(err);
this.stop(err as Error);
return false;
}
} else if (err.message === "consumer not found") {
} else if ((err as Error).message === "consumer not found") {
notFound++;
this.notify(ConsumerEvents.ConsumerNotFound, notFound);
if (!this.isConsume || this.abortOnMissingResource) {
if (this.consumer.ordered) {
const ocs = this.consumer.orderedConsumerState!;
ocs.needsReset = true;
}
this.stop(err);
this.stop(err as Error);
return false;
}
if (this.consumer.ordered) {
Expand Down Expand Up @@ -595,7 +595,7 @@ export class PullConsumerMessagesImpl extends QueuedIteratorImpl<JsMsg>
this.timeout = null;
}

stop(err?: Error) {
override stop(err?: Error) {
if (this.done) {
return;
}
Expand Down
4 changes: 2 additions & 2 deletions jetstream/src/jsclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export class JetStreamManagerImpl extends BaseApiClientImpl
const kind = chunks[chunks.length - 1];
iter.push({ kind: kind as AdvisoryKind, data: d });
} catch (err) {
iter.stop(err);
iter.stop(err as Error);
}
},
});
Expand Down Expand Up @@ -676,7 +676,7 @@ export class JetStreamClientImpl extends BaseApiClientImpl
}
} catch (err) {
//consumer doesn't exist
if (err.code !== "404") {
if ((err as NatsError).code !== "404") {
throw err;
}
}
Expand Down
2 changes: 1 addition & 1 deletion jetstream/src/jslister.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class ListerImpl<T> implements Lister<T>, AsyncIterable<T> {
this.offset += count;
return this.filter(r);
} catch (err) {
this.err = err;
this.err = err as Error;
throw err;
}
}
Expand Down
2 changes: 1 addition & 1 deletion jetstream/src/jsmconsumer_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export class ConsumerAPIImpl extends BaseApiClientImpl implements ConsumerAPI {
minValidation("name", name);
} catch (err) {
// if we have a cannot contain the message, massage a bit
const m = err.message;
const m = (err as Error).message;
const idx = m.indexOf("cannot contain");
if (idx !== -1) {
throw new Error(`consumer 'name' ${m.substring(idx)}`);
Expand Down
5 changes: 3 additions & 2 deletions jetstream/src/jsmsg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import type {
Msg,
MsgHdrs,
MsgImpl,
NatsError,
ProtocolHandler,
RequestOptions,
} from "@nats-io/nats-core/internal";
Expand Down Expand Up @@ -256,13 +257,13 @@ export class JsMsgImpl implements JsMsg {
},
);
} catch (err) {
r.cancel(err);
r.cancel(err as NatsError);
}
try {
await Promise.race([r.timer, r.deferred]);
d.resolve(true);
} catch (err) {
r.cancel(err);
r.cancel(err as NatsError);
d.reject(err);
}
} else {
Expand Down
4 changes: 2 additions & 2 deletions jetstream/src/pushconsumer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export class PushConsumerMessagesImpl extends QueuedIteratorImpl<JsMsg>
return this.iterClosed;
}

stop(err?: Error) {
override stop(err?: Error) {
if (this.done) {
return;
}
Expand Down Expand Up @@ -207,7 +207,7 @@ export class PushConsumerMessagesImpl extends QueuedIteratorImpl<JsMsg>
fn();
}
} catch (err) {
this.stop(err);
this.stop(err as Error);
}
}
}
Expand Down
Loading

0 comments on commit 48eec73

Please sign in to comment.