diff --git a/packages/indexer-nibi/src/gql.ts b/packages/indexer-nibi/src/gql.ts index 30884feb..b18286d2 100644 --- a/packages/indexer-nibi/src/gql.ts +++ b/packages/indexer-nibi/src/gql.ts @@ -48,16 +48,15 @@ export const convertObjectToPropertiesString = (obj: any) => { export const cleanResponse = async (rawResp: Response) => { const respJson = await rawResp.json().catch((err) => { console.error(err) + return undefined }) // console.debug("DEBUG respJson: %o", respJson) - if (!rawResp.ok || !respJson) { - throw new Error(`${JSON.stringify(respJson)}`) - } else if (respJson.data) { + if (respJson?.data) { return respJson.data - } else { - return respJson } + + return respJson } export const gqlQuery = ( diff --git a/packages/indexer-nibi/src/heart-monitor.test.ts b/packages/indexer-nibi/src/heart-monitor.test.ts index 68333a62..f1050e7b 100644 --- a/packages/indexer-nibi/src/heart-monitor.test.ts +++ b/packages/indexer-nibi/src/heart-monitor.test.ts @@ -1045,15 +1045,13 @@ describe("gql cleanResponse", () => { expect(result).toEqual({ key: "value" }) }) - test("should throw an error if rawResp is not ok", async () => { + test("should return an error if rawResp is not ok", async () => { const error = { error: "Error message" } const rawResp = { ok: false, json: () => Promise.resolve(error), } as Response - await expect(cleanResponse(rawResp)).rejects.toThrowError( - `${JSON.stringify(error)}` - ) + expect(await cleanResponse(rawResp)).toEqual(error) }) test("should throw an error if unable to parse JSON", async () => { @@ -1061,6 +1059,6 @@ describe("gql cleanResponse", () => { ok: true, json: () => Promise.reject(new Error("invalid json")), } as Response - await expect(cleanResponse(rawResp)).rejects.toThrowError(``) + expect(await cleanResponse(rawResp)).toEqual(undefined) }) }) diff --git a/packages/nibijs/docs/classes/StableSwap.md b/packages/nibijs/docs/classes/StableSwap.md index ca1495ed..4b05b84b 100644 --- a/packages/nibijs/docs/classes/StableSwap.md +++ b/packages/nibijs/docs/classes/StableSwap.md @@ -178,7 +178,7 @@ y() Calculate x[j] if one makes x[i] = x Done by solving quadratic equation iteratively. -x*1**2 + x1 * (sum' - (A*n**n - 1) * D / (A _ n**n)) = D ** (n+1)/(n \*\* (2 _ n) \_ prod' \* A) +x*1\*\*2 + x1 * (sum' - (A*n\*\*n - 1) * D / (A _ n**n)) = D ** (n+1)/(n \*\* (2 _ n) \_ prod' \* A) x_1\*\*2 + b\*x_1 = c x_1 = (x_1\**2 + c) / (2*x_1 + b) diff --git a/packages/nibijs/src/chain/parse.ts b/packages/nibijs/src/chain/parse.ts index d6cb51a1..3f203c7f 100644 --- a/packages/nibijs/src/chain/parse.ts +++ b/packages/nibijs/src/chain/parse.ts @@ -4,7 +4,7 @@ export const INT_MULT = 1_000_000 /** * toSdkDec converts the input float string to an sdk.Dec. * The maximum number of decimal places for an sdk.Dec is 18. - * NOTE: An error is thrown if more decimal digits are provided than the + * NOTE: An error is console'd if more decimal digits are provided than the * precision, 18. * * ref: Reimplementation of cosmos-sdk/types/decimal.go diff --git a/packages/nibijs/src/chain/types.ts b/packages/nibijs/src/chain/types.ts index 749b8709..4e44e2b1 100644 --- a/packages/nibijs/src/chain/types.ts +++ b/packages/nibijs/src/chain/types.ts @@ -12,8 +12,10 @@ export const go = async (promise: Promise) => { export const assert = (condition: boolean, message?: string) => { if (!condition) { const errMsg = message ? `AssertionError: ${message}` : "AssertionError" - throw new Error(errMsg) + console.error(Error(errMsg)) + return errMsg } + return true } export interface CoinMap { diff --git a/packages/nibijs/src/chain/useFaucet.ts b/packages/nibijs/src/chain/useFaucet.ts index 95c0ae92..772e3f2d 100644 --- a/packages/nibijs/src/chain/useFaucet.ts +++ b/packages/nibijs/src/chain/useFaucet.ts @@ -14,7 +14,7 @@ export async function useFaucet({ chain: Chain amts?: { nibi: number; nusd: number; usdt: number } grecaptcha: string -}): Promise { +}): Promise { if (!amts) { // default values amts = { @@ -48,7 +48,7 @@ export async function useFaucet({ body: JSON.stringify({ address, coins, grecaptcha }), }).catch((err) => { console.error(err) - throw err + return undefined }) } diff --git a/packages/nibijs/src/stableswap/stableswap.ts b/packages/nibijs/src/stableswap/stableswap.ts index 2eb34c64..dcb05177 100644 --- a/packages/nibijs/src/stableswap/stableswap.ts +++ b/packages/nibijs/src/stableswap/stableswap.ts @@ -150,7 +150,8 @@ export class StableSwap { .dividedBy(BigNumber(10).exponentiatedBy(BigNumber(10))) if (dy.isLessThanOrEqualTo(BigNumber(0))) { - throw new Error("Invalid exchange operation") + console.error(Error("Invalid exchange operation")) + return BigNumber(0) } return dy.minus(fee) diff --git a/packages/nibijs/src/test/chain.test.ts b/packages/nibijs/src/test/chain.test.ts index a02f9d9f..f38aba0f 100644 --- a/packages/nibijs/src/test/chain.test.ts +++ b/packages/nibijs/src/test/chain.test.ts @@ -190,7 +190,7 @@ describe("chain/types", () => { }) test("custom assert fn", () => { - expect(() => assert(false)).toThrow() + expect(assert(false)).toEqual("AssertionError") const err = "useful error message" - expect(() => assert(false, err)).toThrow(err) + expect(assert(false, err)).toEqual(`AssertionError: ${err}`) }) diff --git a/packages/nibijs/src/test/faucet.test.ts b/packages/nibijs/src/test/faucet.test.ts index f8fde098..b0ff8922 100644 --- a/packages/nibijs/src/test/faucet.test.ts +++ b/packages/nibijs/src/test/faucet.test.ts @@ -51,7 +51,7 @@ test.skip("faucet utility works", async () => { chain: TEST_CHAIN, grecaptcha: "", }) - expect(faucetResp.ok).toBeTruthy() + expect(faucetResp?.ok).toBeTruthy() const balancesEnd = newCoinMapFromCoins( await signingClient.getAllBalances(toAddr) @@ -107,7 +107,7 @@ describe("useFaucet", () => { }) }) - test("should throw an error if fetch fails", async () => { + test("should return undefined if fetch fails", async () => { const errorMessage = "Failed to fetch" jest.mock("cross-fetch", () => ({ diff --git a/packages/nibijs/src/test/stableswap.test.ts b/packages/nibijs/src/test/stableswap.test.ts index 62eda12c..e2afc3b1 100644 --- a/packages/nibijs/src/test/stableswap.test.ts +++ b/packages/nibijs/src/test/stableswap.test.ts @@ -16,7 +16,8 @@ describe("stableswap tests", () => { /"(\[[^"]+\])",(\d+),(\d+),(\d+),(\d+(\.\d+)?),(\d+(\.\d+)?)/ const match = line.match(regex) if (!match) { - throw new Error("Invalid line format") + console.error(new Error("Invalid line format")) + return } const balances = JSON.parse(match[1]) as BigNumber[] @@ -40,8 +41,6 @@ describe("stableswap tests", () => { const amplification = BigNumber(0) const curveModel = new StableSwap(amplification, balances, BigNumber(0)) - expect(() => curveModel.exchange(0, 1, BigNumber(0))).toThrow( - "Invalid exchange operation" - ) + expect(curveModel.exchange(0, 1, BigNumber(0))).toEqual(BigNumber(0)) }) }) diff --git a/packages/protojs/src/cosmos/base/query/v1beta1/pagination.ts b/packages/protojs/src/cosmos/base/query/v1beta1/pagination.ts index a50ba238..69857c34 100644 --- a/packages/protojs/src/cosmos/base/query/v1beta1/pagination.ts +++ b/packages/protojs/src/cosmos/base/query/v1beta1/pagination.ts @@ -306,7 +306,8 @@ var tsProtoGlobalThis: any = (() => { if (typeof global !== "undefined") { return global } - throw "Unable to locate global object" + console.error("Unable to locate global object") + return undefined })() function bytesFromBase64(b64: string): Uint8Array { diff --git a/packages/protojs/src/google/protobuf/any.ts b/packages/protojs/src/google/protobuf/any.ts index ad12327e..df65ad42 100644 --- a/packages/protojs/src/google/protobuf/any.ts +++ b/packages/protojs/src/google/protobuf/any.ts @@ -219,7 +219,8 @@ var tsProtoGlobalThis: any = (() => { if (typeof global !== "undefined") { return global } - throw "Unable to locate global object" + console.error("Unable to locate global object") + return undefined })() function bytesFromBase64(b64: string): Uint8Array {