@usherlabs/cex-broker 0.2.21 → 0.2.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/cli.js +32 -11
- package/dist/handlers/execute-action/context.d.ts +5 -0
- package/dist/helpers/shared/errors.d.ts +10 -0
- package/dist/index.js +33 -12
- package/dist/index.js.map +11 -11
- package/package.json +1 -1
package/dist/commands/cli.js
CHANGED
|
@@ -316403,9 +316403,23 @@ var grpc14 = __toESM(require_src3(), 1);
|
|
|
316403
316403
|
var grpc3 = __toESM(require_src3(), 1);
|
|
316404
316404
|
|
|
316405
316405
|
// src/helpers/shared/errors.ts
|
|
316406
|
+
var MAX_ERROR_DETAIL_LENGTH = 512;
|
|
316406
316407
|
function getErrorMessage(error) {
|
|
316407
316408
|
return error instanceof Error ? error.message : typeof error === "string" ? error : "Unknown error";
|
|
316408
316409
|
}
|
|
316410
|
+
function errorClassName(error) {
|
|
316411
|
+
if (!(error instanceof Error)) {
|
|
316412
|
+
return;
|
|
316413
|
+
}
|
|
316414
|
+
const name = error.constructor?.name || error.name;
|
|
316415
|
+
return name && name !== "Error" ? name : undefined;
|
|
316416
|
+
}
|
|
316417
|
+
function sanitizeErrorDetail(error) {
|
|
316418
|
+
const className = errorClassName(error);
|
|
316419
|
+
const message = getErrorMessage(error);
|
|
316420
|
+
const detail = className ? `${className}: ${message}` : message;
|
|
316421
|
+
return detail.replace(/\s+/g, " ").trim().slice(0, MAX_ERROR_DETAIL_LENGTH);
|
|
316422
|
+
}
|
|
316409
316423
|
function safeLogError(context2, error) {
|
|
316410
316424
|
try {
|
|
316411
316425
|
log.error(context2, { error });
|
|
@@ -330253,6 +330267,12 @@ function rejectWithGrpcError(ctx, error48, options) {
|
|
|
330253
330267
|
} else {
|
|
330254
330268
|
finalMessage = message;
|
|
330255
330269
|
}
|
|
330270
|
+
if (options?.appendClassName) {
|
|
330271
|
+
const className = errorClassName(error48);
|
|
330272
|
+
if (className && !finalMessage.includes(className)) {
|
|
330273
|
+
finalMessage = `${finalMessage} (${className})`;
|
|
330274
|
+
}
|
|
330275
|
+
}
|
|
330256
330276
|
ctx.wrappedCallback({ code, message: finalMessage }, null);
|
|
330257
330277
|
}
|
|
330258
330278
|
|
|
@@ -330425,7 +330445,8 @@ async function handleDeposit(ctx) {
|
|
|
330425
330445
|
}
|
|
330426
330446
|
rejectWithGrpcError(ctx, error48, {
|
|
330427
330447
|
message,
|
|
330428
|
-
prefix: "deposit_observation_unavailable: "
|
|
330448
|
+
prefix: "deposit_observation_unavailable: ",
|
|
330449
|
+
appendClassName: true
|
|
330429
330450
|
});
|
|
330430
330451
|
}
|
|
330431
330452
|
}
|
|
@@ -330744,10 +330765,9 @@ async function handleOrderBookCall(ctx) {
|
|
|
330744
330765
|
});
|
|
330745
330766
|
} catch (error48) {
|
|
330746
330767
|
safeLogError("Order-book Call failed", error48);
|
|
330747
|
-
const message = getErrorMessage(error48);
|
|
330748
330768
|
ctx.wrappedCallback({
|
|
330749
330769
|
code: mapCcxtErrorToGrpcStatus(error48) ?? grpc4.status.INTERNAL,
|
|
330750
|
-
message: `Order-book Call failed: ${
|
|
330770
|
+
message: `Order-book Call failed: ${sanitizeErrorDetail(error48)}`
|
|
330751
330771
|
}, null);
|
|
330752
330772
|
}
|
|
330753
330773
|
return true;
|
|
@@ -330853,7 +330873,7 @@ async function handleInternalTransfer(ctx) {
|
|
|
330853
330873
|
}
|
|
330854
330874
|
ctx.wrappedCallback({
|
|
330855
330875
|
code,
|
|
330856
|
-
message: `InternalTransfer failed: ${
|
|
330876
|
+
message: `InternalTransfer failed: ${sanitizeErrorDetail(error48)}`
|
|
330857
330877
|
}, null);
|
|
330858
330878
|
}
|
|
330859
330879
|
}
|
|
@@ -330950,7 +330970,7 @@ async function handleCreateOrder(ctx) {
|
|
|
330950
330970
|
archiveOrderExecutionInBackground(brokerArchiver, failedCreateContext, undefined, error48);
|
|
330951
330971
|
ctx.wrappedCallback({
|
|
330952
330972
|
code: grpc6.status.INTERNAL,
|
|
330953
|
-
message:
|
|
330973
|
+
message: `Order Creation failed: ${sanitizeErrorDetail(error48)}`
|
|
330954
330974
|
}, null);
|
|
330955
330975
|
}
|
|
330956
330976
|
}
|
|
@@ -331023,7 +331043,7 @@ async function handleGetOrderDetails(ctx) {
|
|
|
331023
331043
|
archiveOrderExecutionInBackground(brokerArchiver, failedGetOrderContext, undefined, error48);
|
|
331024
331044
|
ctx.wrappedCallback({
|
|
331025
331045
|
code: grpc6.status.INTERNAL,
|
|
331026
|
-
message: `Failed to fetch order details from ${cex3}`
|
|
331046
|
+
message: `Failed to fetch order details from ${cex3}: ${sanitizeErrorDetail(error48)}`
|
|
331027
331047
|
}, null);
|
|
331028
331048
|
}
|
|
331029
331049
|
}
|
|
@@ -331087,7 +331107,7 @@ async function handleCancelOrder(ctx) {
|
|
|
331087
331107
|
archiveOrderExecutionInBackground(brokerArchiver, failedCancelContext, undefined, error48);
|
|
331088
331108
|
ctx.wrappedCallback({
|
|
331089
331109
|
code: grpc6.status.INTERNAL,
|
|
331090
|
-
message: `Failed to cancel order from ${cex3}`
|
|
331110
|
+
message: `Failed to cancel order from ${cex3}: ${sanitizeErrorDetail(error48)}`
|
|
331091
331111
|
}, null);
|
|
331092
331112
|
}
|
|
331093
331113
|
}
|
|
@@ -331584,7 +331604,7 @@ async function handleGetPerpConfigState(ctx) {
|
|
|
331584
331604
|
safeLogError(`GetPerpConfigState failed for ${cex3}`, error48);
|
|
331585
331605
|
ctx.wrappedCallback({
|
|
331586
331606
|
code: grpc8.status.INTERNAL,
|
|
331587
|
-
message:
|
|
331607
|
+
message: `GetPerpConfigState failed: ${sanitizeErrorDetail(error48)}`
|
|
331588
331608
|
}, null);
|
|
331589
331609
|
}
|
|
331590
331610
|
}
|
|
@@ -331625,7 +331645,7 @@ async function handleSetPerpConfigState(ctx) {
|
|
|
331625
331645
|
safeLogError(`SetPerpConfigState failed for ${cex3}`, error48);
|
|
331626
331646
|
ctx.wrappedCallback({
|
|
331627
331647
|
code: grpc8.status.INTERNAL,
|
|
331628
|
-
message:
|
|
331648
|
+
message: `SetPerpConfigState failed: ${sanitizeErrorDetail(error48)}`
|
|
331629
331649
|
}, null);
|
|
331630
331650
|
}
|
|
331631
331651
|
}
|
|
@@ -331676,7 +331696,8 @@ async function handleTreasuryCall(ctx) {
|
|
|
331676
331696
|
safeLogError("Call failed", error48);
|
|
331677
331697
|
rejectWithGrpcError(ctx, error48, {
|
|
331678
331698
|
message: getErrorMessage(error48),
|
|
331679
|
-
preferStableMessageOnly: true
|
|
331699
|
+
preferStableMessageOnly: true,
|
|
331700
|
+
appendClassName: true
|
|
331680
331701
|
});
|
|
331681
331702
|
}
|
|
331682
331703
|
}
|
|
@@ -331798,7 +331819,7 @@ async function handleWithdraw(ctx) {
|
|
|
331798
331819
|
const code = mapCcxtErrorToGrpcStatus(error48) ?? grpc10.status.INTERNAL;
|
|
331799
331820
|
ctx.wrappedCallback({
|
|
331800
331821
|
code,
|
|
331801
|
-
message: `Withdraw failed: ${
|
|
331822
|
+
message: `Withdraw failed: ${sanitizeErrorDetail(error48)}`
|
|
331802
331823
|
}, null);
|
|
331803
331824
|
}
|
|
331804
331825
|
}
|
|
@@ -40,5 +40,10 @@ export declare function rejectWithGrpcError(ctx: ExecuteActionContext, error: un
|
|
|
40
40
|
message?: string;
|
|
41
41
|
prefix?: string;
|
|
42
42
|
preferStableMessageOnly?: boolean;
|
|
43
|
+
/** Append the caught error's class name (e.g. InsufficientFunds) as a
|
|
44
|
+
* suffix. It goes last, not in front, because the gRPC status code is
|
|
45
|
+
* derived from the raw message via stableGrpcErrorCode; prepending the
|
|
46
|
+
* class name would break that prefix match. */
|
|
47
|
+
appendClassName?: boolean;
|
|
43
48
|
}): void;
|
|
44
49
|
export declare function successWithProof(ctx: ExecuteActionContext, result: unknown): void;
|
|
@@ -1,2 +1,12 @@
|
|
|
1
1
|
export declare function getErrorMessage(error: unknown): string;
|
|
2
|
+
/** Constructor/class name of a caught error (ccxt classes like InsufficientFunds,
|
|
3
|
+
* BadSymbol, OrderNotFound carry the actionable signal). The generic `Error` name
|
|
4
|
+
* adds nothing, so it is dropped; returns undefined for non-Error values. */
|
|
5
|
+
export declare function errorClassName(error: unknown): string | undefined;
|
|
6
|
+
/** Sanitized, single-line, length-capped detail for a caught error: the venue
|
|
7
|
+
* error class name plus its message. Safe to return to gRPC callers — it carries
|
|
8
|
+
* only the exchange's own error text (class + message), never a stack or payload,
|
|
9
|
+
* so downstream consumers can distinguish e.g. InsufficientFunds from BadSymbol
|
|
10
|
+
* instead of an opaque "<action> failed". */
|
|
11
|
+
export declare function sanitizeErrorDetail(error: unknown): string;
|
|
2
12
|
export declare function safeLogError(context: string, error: unknown): void;
|
package/dist/index.js
CHANGED
|
@@ -279355,9 +279355,23 @@ import * as grpc14 from "@grpc/grpc-js";
|
|
|
279355
279355
|
import * as grpc3 from "@grpc/grpc-js";
|
|
279356
279356
|
|
|
279357
279357
|
// src/helpers/shared/errors.ts
|
|
279358
|
+
var MAX_ERROR_DETAIL_LENGTH = 512;
|
|
279358
279359
|
function getErrorMessage(error) {
|
|
279359
279360
|
return error instanceof Error ? error.message : typeof error === "string" ? error : "Unknown error";
|
|
279360
279361
|
}
|
|
279362
|
+
function errorClassName(error) {
|
|
279363
|
+
if (!(error instanceof Error)) {
|
|
279364
|
+
return;
|
|
279365
|
+
}
|
|
279366
|
+
const name = error.constructor?.name || error.name;
|
|
279367
|
+
return name && name !== "Error" ? name : undefined;
|
|
279368
|
+
}
|
|
279369
|
+
function sanitizeErrorDetail(error) {
|
|
279370
|
+
const className = errorClassName(error);
|
|
279371
|
+
const message = getErrorMessage(error);
|
|
279372
|
+
const detail = className ? `${className}: ${message}` : message;
|
|
279373
|
+
return detail.replace(/\s+/g, " ").trim().slice(0, MAX_ERROR_DETAIL_LENGTH);
|
|
279374
|
+
}
|
|
279361
279375
|
function safeLogError(context3, error) {
|
|
279362
279376
|
try {
|
|
279363
279377
|
log.error(context3, { error });
|
|
@@ -293205,6 +293219,12 @@ function rejectWithGrpcError(ctx, error48, options) {
|
|
|
293205
293219
|
} else {
|
|
293206
293220
|
finalMessage = message;
|
|
293207
293221
|
}
|
|
293222
|
+
if (options?.appendClassName) {
|
|
293223
|
+
const className = errorClassName(error48);
|
|
293224
|
+
if (className && !finalMessage.includes(className)) {
|
|
293225
|
+
finalMessage = `${finalMessage} (${className})`;
|
|
293226
|
+
}
|
|
293227
|
+
}
|
|
293208
293228
|
ctx.wrappedCallback({ code, message: finalMessage }, null);
|
|
293209
293229
|
}
|
|
293210
293230
|
|
|
@@ -293377,7 +293397,8 @@ async function handleDeposit(ctx) {
|
|
|
293377
293397
|
}
|
|
293378
293398
|
rejectWithGrpcError(ctx, error48, {
|
|
293379
293399
|
message,
|
|
293380
|
-
prefix: "deposit_observation_unavailable: "
|
|
293400
|
+
prefix: "deposit_observation_unavailable: ",
|
|
293401
|
+
appendClassName: true
|
|
293381
293402
|
});
|
|
293382
293403
|
}
|
|
293383
293404
|
}
|
|
@@ -293696,10 +293717,9 @@ async function handleOrderBookCall(ctx) {
|
|
|
293696
293717
|
});
|
|
293697
293718
|
} catch (error48) {
|
|
293698
293719
|
safeLogError("Order-book Call failed", error48);
|
|
293699
|
-
const message = getErrorMessage(error48);
|
|
293700
293720
|
ctx.wrappedCallback({
|
|
293701
293721
|
code: mapCcxtErrorToGrpcStatus(error48) ?? grpc4.status.INTERNAL,
|
|
293702
|
-
message: `Order-book Call failed: ${
|
|
293722
|
+
message: `Order-book Call failed: ${sanitizeErrorDetail(error48)}`
|
|
293703
293723
|
}, null);
|
|
293704
293724
|
}
|
|
293705
293725
|
return true;
|
|
@@ -293805,7 +293825,7 @@ async function handleInternalTransfer(ctx) {
|
|
|
293805
293825
|
}
|
|
293806
293826
|
ctx.wrappedCallback({
|
|
293807
293827
|
code,
|
|
293808
|
-
message: `InternalTransfer failed: ${
|
|
293828
|
+
message: `InternalTransfer failed: ${sanitizeErrorDetail(error48)}`
|
|
293809
293829
|
}, null);
|
|
293810
293830
|
}
|
|
293811
293831
|
}
|
|
@@ -293902,7 +293922,7 @@ async function handleCreateOrder(ctx) {
|
|
|
293902
293922
|
archiveOrderExecutionInBackground(brokerArchiver, failedCreateContext, undefined, error48);
|
|
293903
293923
|
ctx.wrappedCallback({
|
|
293904
293924
|
code: grpc6.status.INTERNAL,
|
|
293905
|
-
message:
|
|
293925
|
+
message: `Order Creation failed: ${sanitizeErrorDetail(error48)}`
|
|
293906
293926
|
}, null);
|
|
293907
293927
|
}
|
|
293908
293928
|
}
|
|
@@ -293975,7 +293995,7 @@ async function handleGetOrderDetails(ctx) {
|
|
|
293975
293995
|
archiveOrderExecutionInBackground(brokerArchiver, failedGetOrderContext, undefined, error48);
|
|
293976
293996
|
ctx.wrappedCallback({
|
|
293977
293997
|
code: grpc6.status.INTERNAL,
|
|
293978
|
-
message: `Failed to fetch order details from ${cex3}`
|
|
293998
|
+
message: `Failed to fetch order details from ${cex3}: ${sanitizeErrorDetail(error48)}`
|
|
293979
293999
|
}, null);
|
|
293980
294000
|
}
|
|
293981
294001
|
}
|
|
@@ -294039,7 +294059,7 @@ async function handleCancelOrder(ctx) {
|
|
|
294039
294059
|
archiveOrderExecutionInBackground(brokerArchiver, failedCancelContext, undefined, error48);
|
|
294040
294060
|
ctx.wrappedCallback({
|
|
294041
294061
|
code: grpc6.status.INTERNAL,
|
|
294042
|
-
message: `Failed to cancel order from ${cex3}`
|
|
294062
|
+
message: `Failed to cancel order from ${cex3}: ${sanitizeErrorDetail(error48)}`
|
|
294043
294063
|
}, null);
|
|
294044
294064
|
}
|
|
294045
294065
|
}
|
|
@@ -294536,7 +294556,7 @@ async function handleGetPerpConfigState(ctx) {
|
|
|
294536
294556
|
safeLogError(`GetPerpConfigState failed for ${cex3}`, error48);
|
|
294537
294557
|
ctx.wrappedCallback({
|
|
294538
294558
|
code: grpc8.status.INTERNAL,
|
|
294539
|
-
message:
|
|
294559
|
+
message: `GetPerpConfigState failed: ${sanitizeErrorDetail(error48)}`
|
|
294540
294560
|
}, null);
|
|
294541
294561
|
}
|
|
294542
294562
|
}
|
|
@@ -294577,7 +294597,7 @@ async function handleSetPerpConfigState(ctx) {
|
|
|
294577
294597
|
safeLogError(`SetPerpConfigState failed for ${cex3}`, error48);
|
|
294578
294598
|
ctx.wrappedCallback({
|
|
294579
294599
|
code: grpc8.status.INTERNAL,
|
|
294580
|
-
message:
|
|
294600
|
+
message: `SetPerpConfigState failed: ${sanitizeErrorDetail(error48)}`
|
|
294581
294601
|
}, null);
|
|
294582
294602
|
}
|
|
294583
294603
|
}
|
|
@@ -294628,7 +294648,8 @@ async function handleTreasuryCall(ctx) {
|
|
|
294628
294648
|
safeLogError("Call failed", error48);
|
|
294629
294649
|
rejectWithGrpcError(ctx, error48, {
|
|
294630
294650
|
message: getErrorMessage(error48),
|
|
294631
|
-
preferStableMessageOnly: true
|
|
294651
|
+
preferStableMessageOnly: true,
|
|
294652
|
+
appendClassName: true
|
|
294632
294653
|
});
|
|
294633
294654
|
}
|
|
294634
294655
|
}
|
|
@@ -294750,7 +294771,7 @@ async function handleWithdraw(ctx) {
|
|
|
294750
294771
|
const code = mapCcxtErrorToGrpcStatus(error48) ?? grpc10.status.INTERNAL;
|
|
294751
294772
|
ctx.wrappedCallback({
|
|
294752
294773
|
code,
|
|
294753
|
-
message: `Withdraw failed: ${
|
|
294774
|
+
message: `Withdraw failed: ${sanitizeErrorDetail(error48)}`
|
|
294754
294775
|
}, null);
|
|
294755
294776
|
}
|
|
294756
294777
|
}
|
|
@@ -296827,4 +296848,4 @@ export {
|
|
|
296827
296848
|
CEXBroker as default
|
|
296828
296849
|
};
|
|
296829
296850
|
|
|
296830
|
-
//# debugId=
|
|
296851
|
+
//# debugId=6EFE98438C50664564756E2164756E21
|