Skip to content

Commit fa63d10

Browse files
authored
fix: improve leader failover reconnection and error mapping (#480)
* chore(deps): update @kurrent/bridge to 0.1.5 * fix: improve error mapping for leader failover reconnection * fix: clean up bridge error conversion and add debug logging
1 parent 72f5dda commit fa63d10

File tree

5 files changed

+61
-62
lines changed

5 files changed

+61
-62
lines changed

packages/benchmark/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
},
1212
"dependencies": {
1313
"@eventstore/db-client": "^6.2.1",
14-
"@kurrent/bridge": "^0.1.3",
14+
"@kurrent/bridge": "^0.1.5",
1515
"tinybench": "^3.1.1"
1616
},
1717
"devDependencies": {

packages/db-client/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
},
4747
"dependencies": {
4848
"@grpc/grpc-js": "^1.14.3",
49-
"@kurrent/bridge": "^0.1.3",
49+
"@kurrent/bridge": "^0.1.5",
5050
"@types/debug": "^4.1.12",
5151
"@types/google-protobuf": "^3.15.12",
5252
"@types/node": "^22.10.2",

packages/db-client/src/utils/CommandError.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,8 @@ export const convertToCommandError = (error: Error): CommandError | Error => {
640640
case StatusCode.DEADLINE_EXCEEDED:
641641
return new DeadlineExceededError(error);
642642
case StatusCode.UNAVAILABLE:
643+
case StatusCode.INTERNAL:
644+
case StatusCode.DATA_LOSS:
643645
return new UnavailableError(error);
644646
case StatusCode.UNAUTHENTICATED:
645647
return new AccessDeniedError(error);

packages/db-client/src/utils/convertBridgeError.ts

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,43 +3,40 @@ import {
33
StreamNotFoundError,
44
StreamDeletedError,
55
AccessDeniedError,
6+
UnavailableError,
7+
DeadlineExceededError,
8+
UnknownError,
69
} from "./CommandError";
10+
import { debug } from "./debug";
711
import { ServiceError } from "@grpc/grpc-js";
812

9-
// export const convertBridgeError = (
10-
// error: ServiceError,
11-
// streamName?: string
12-
// ) => {
13-
// const stream = streamName ?? "unknown stream";
14-
//
15-
// switch (error.name) {
16-
// case StreamNotFoundError.name:
17-
// throw new StreamNotFoundError(error, stream);
18-
// case StreamDeletedError.name:
19-
// throw StreamDeletedError.fromStreamName(stream);
20-
// case NotLeaderError.name:
21-
// throw new NotLeaderError(error);
22-
// case AccessDeniedError.name:
23-
// throw new AccessDeniedError(error);
24-
// default:
25-
// throw error;
26-
// }
27-
// };
28-
2913
export const convertBridgeError = (error: Error, streamName?: string) => {
3014
const stream = streamName ?? "unknown stream";
15+
16+
// Bridge errors are plain Error objects from the Rust native addon with
17+
// name, message, and metadata (plain object). They lack gRPC-specific
18+
// ServiceError properties (code, details) but CommandErrorBase handles this.
3119
const serviceError = error as ServiceError;
3220

3321
switch (error.name) {
34-
case StreamNotFoundError.name:
22+
case "StreamNotFoundError":
3523
return new StreamNotFoundError(serviceError, stream);
36-
case StreamDeletedError.name:
24+
case "StreamDeletedError":
3725
return StreamDeletedError.fromStreamName(stream);
38-
case NotLeaderError.name:
26+
case "NotLeaderError":
3927
return new NotLeaderError(serviceError);
40-
case AccessDeniedError.name:
28+
case "AccessDeniedError":
4129
return new AccessDeniedError(serviceError);
30+
case "UnavailableError":
31+
return new UnavailableError(serviceError);
32+
case "DeadlineExceededError":
33+
return new DeadlineExceededError(serviceError);
4234
default:
43-
return error;
35+
debug.connection(
36+
"Unrecognized bridge error type '%s': %s",
37+
error.name,
38+
error.message
39+
);
40+
return new UnknownError(serviceError);
4441
}
4542
};

yarn.lock

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,66 +1065,66 @@ __metadata:
10651065
languageName: node
10661066
linkType: hard
10671067

1068-
"@kurrent/bridge-darwin-arm64@npm:0.1.3":
1069-
version: 0.1.3
1070-
resolution: "@kurrent/bridge-darwin-arm64@npm:0.1.3"
1068+
"@kurrent/bridge-darwin-arm64@npm:0.1.5":
1069+
version: 0.1.5
1070+
resolution: "@kurrent/bridge-darwin-arm64@npm:0.1.5"
10711071
conditions: os=darwin & cpu=arm64
10721072
languageName: node
10731073
linkType: hard
10741074

1075-
"@kurrent/bridge-darwin-x64@npm:0.1.3":
1076-
version: 0.1.3
1077-
resolution: "@kurrent/bridge-darwin-x64@npm:0.1.3"
1075+
"@kurrent/bridge-darwin-x64@npm:0.1.5":
1076+
version: 0.1.5
1077+
resolution: "@kurrent/bridge-darwin-x64@npm:0.1.5"
10781078
conditions: os=darwin & cpu=x64
10791079
languageName: node
10801080
linkType: hard
10811081

1082-
"@kurrent/bridge-linux-arm64-gnu@npm:0.1.3":
1083-
version: 0.1.3
1084-
resolution: "@kurrent/bridge-linux-arm64-gnu@npm:0.1.3"
1082+
"@kurrent/bridge-linux-arm64-gnu@npm:0.1.5":
1083+
version: 0.1.5
1084+
resolution: "@kurrent/bridge-linux-arm64-gnu@npm:0.1.5"
10851085
conditions: os=linux & cpu=arm64
10861086
languageName: node
10871087
linkType: hard
10881088

1089-
"@kurrent/bridge-linux-arm64-musl@npm:0.1.3":
1090-
version: 0.1.3
1091-
resolution: "@kurrent/bridge-linux-arm64-musl@npm:0.1.3"
1089+
"@kurrent/bridge-linux-arm64-musl@npm:0.1.5":
1090+
version: 0.1.5
1091+
resolution: "@kurrent/bridge-linux-arm64-musl@npm:0.1.5"
10921092
conditions: os=linux & cpu=arm64
10931093
languageName: node
10941094
linkType: hard
10951095

1096-
"@kurrent/bridge-linux-x64-gnu@npm:0.1.3":
1097-
version: 0.1.3
1098-
resolution: "@kurrent/bridge-linux-x64-gnu@npm:0.1.3"
1096+
"@kurrent/bridge-linux-x64-gnu@npm:0.1.5":
1097+
version: 0.1.5
1098+
resolution: "@kurrent/bridge-linux-x64-gnu@npm:0.1.5"
10991099
conditions: os=linux & cpu=x64
11001100
languageName: node
11011101
linkType: hard
11021102

1103-
"@kurrent/bridge-linux-x64-musl@npm:0.1.3":
1104-
version: 0.1.3
1105-
resolution: "@kurrent/bridge-linux-x64-musl@npm:0.1.3"
1103+
"@kurrent/bridge-linux-x64-musl@npm:0.1.5":
1104+
version: 0.1.5
1105+
resolution: "@kurrent/bridge-linux-x64-musl@npm:0.1.5"
11061106
conditions: os=linux & cpu=x64
11071107
languageName: node
11081108
linkType: hard
11091109

1110-
"@kurrent/bridge-win32-x64-msvc@npm:0.1.3":
1111-
version: 0.1.3
1112-
resolution: "@kurrent/bridge-win32-x64-msvc@npm:0.1.3"
1110+
"@kurrent/bridge-win32-x64-msvc@npm:0.1.5":
1111+
version: 0.1.5
1112+
resolution: "@kurrent/bridge-win32-x64-msvc@npm:0.1.5"
11131113
conditions: os=win32 & cpu=x64
11141114
languageName: node
11151115
linkType: hard
11161116

1117-
"@kurrent/bridge@npm:^0.1.3":
1118-
version: 0.1.3
1119-
resolution: "@kurrent/bridge@npm:0.1.3"
1120-
dependencies:
1121-
"@kurrent/bridge-darwin-arm64": "npm:0.1.3"
1122-
"@kurrent/bridge-darwin-x64": "npm:0.1.3"
1123-
"@kurrent/bridge-linux-arm64-gnu": "npm:0.1.3"
1124-
"@kurrent/bridge-linux-arm64-musl": "npm:0.1.3"
1125-
"@kurrent/bridge-linux-x64-gnu": "npm:0.1.3"
1126-
"@kurrent/bridge-linux-x64-musl": "npm:0.1.3"
1127-
"@kurrent/bridge-win32-x64-msvc": "npm:0.1.3"
1117+
"@kurrent/bridge@npm:^0.1.5":
1118+
version: 0.1.5
1119+
resolution: "@kurrent/bridge@npm:0.1.5"
1120+
dependencies:
1121+
"@kurrent/bridge-darwin-arm64": "npm:0.1.5"
1122+
"@kurrent/bridge-darwin-x64": "npm:0.1.5"
1123+
"@kurrent/bridge-linux-arm64-gnu": "npm:0.1.5"
1124+
"@kurrent/bridge-linux-arm64-musl": "npm:0.1.5"
1125+
"@kurrent/bridge-linux-x64-gnu": "npm:0.1.5"
1126+
"@kurrent/bridge-linux-x64-musl": "npm:0.1.5"
1127+
"@kurrent/bridge-win32-x64-msvc": "npm:0.1.5"
11281128
"@neon-rs/load": "npm:^0.1.82"
11291129
dependenciesMeta:
11301130
"@kurrent/bridge-darwin-arm64":
@@ -1141,7 +1141,7 @@ __metadata:
11411141
optional: true
11421142
"@kurrent/bridge-win32-x64-msvc":
11431143
optional: true
1144-
checksum: 10c0/76c89f2fd392577a815c23d81332f052e1c3d30984c34e64ca6b7271ca2e1d713348dd44454e5d33d5b7935b33d7d143382c82c396bfa25c168678e05b3e387d
1144+
checksum: 10c0/8f1941011c17cd81b29e78b4743097fa8c6452abe2c80acee23c24d4b665ae027172bbb31d805d21a15ab42caa5e8ac83699a040434a53a0df14bcf7cf4a69b9
11451145
languageName: node
11461146
linkType: hard
11471147

@@ -1150,7 +1150,7 @@ __metadata:
11501150
resolution: "@kurrent/kurrentdb-client@workspace:packages/db-client"
11511151
dependencies:
11521152
"@grpc/grpc-js": "npm:^1.14.3"
1153-
"@kurrent/bridge": "npm:^0.1.3"
1153+
"@kurrent/bridge": "npm:^0.1.5"
11541154
"@types/debug": "npm:^4.1.12"
11551155
"@types/google-protobuf": "npm:^3.15.12"
11561156
"@types/node": "npm:^22.10.2"
@@ -2740,7 +2740,7 @@ __metadata:
27402740
resolution: "benchmark@workspace:packages/benchmark"
27412741
dependencies:
27422742
"@eventstore/db-client": "npm:^6.2.1"
2743-
"@kurrent/bridge": "npm:^0.1.3"
2743+
"@kurrent/bridge": "npm:^0.1.5"
27442744
"@kurrent/kurrentdb-client": "workspace:^"
27452745
clinic: "npm:^13.0.0"
27462746
tinybench: "npm:^3.1.1"

0 commit comments

Comments
 (0)