Skip to content

Commit

Permalink
Fix custom error handling (#2210)
Browse files Browse the repository at this point in the history
  • Loading branch information
dianasavvatina authored Dec 9, 2024
1 parent b3ef307 commit 013b870
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { mockToast, useRestoreBackup } from "@umami/state";
import { fileUploadMock, umamiBackup } from "@umami/test-utils";
import { CustomError } from "@umami/utils";

import { RestoreBackupFile } from "./RestoreBackupFile";
import {
Expand Down Expand Up @@ -41,7 +42,9 @@ describe("<RestoreBackupFile />", () => {
it("shows error for wrong backup file format", async () => {
jest
.mocked(useRestoreBackup)
.mockImplementation(() => jest.fn(() => Promise.reject("Invalid backup file.")));
.mockImplementation(() =>
jest.fn(() => Promise.reject(new CustomError("Invalid backup file.")))
);
const user = userEvent.setup();

render(<RestoreBackupFile />);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
} from "@umami/core";
import { type UmamiStore, addTestAccount, assetsActions, makeStore, mockToast } from "@umami/state";
import { executeParams } from "@umami/test-utils";
import { CustomError } from "@umami/utils";

import { FormPage, type FormValues } from "./FormPage";
import { SignPage } from "./SignPage";
Expand Down Expand Up @@ -158,7 +159,7 @@ describe("<Form />", () => {
});

const estimateMock = jest.mocked(estimate);
estimateMock.mockRejectedValue(new Error("Some error occurred"));
estimateMock.mockRejectedValue(new CustomError("Some error occurred"));

await act(() => user.click(submitButton));

Expand Down
3 changes: 2 additions & 1 deletion apps/desktop/src/components/SendFlow/Tez/FormPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
} from "@umami/core";
import { type UmamiStore, addTestAccount, makeStore, mockToast } from "@umami/state";
import { executeParams } from "@umami/test-utils";
import { CustomError } from "@umami/utils";

import { FormPage, type FormValues } from "./FormPage";
import { SignPage } from "./SignPage";
Expand Down Expand Up @@ -241,7 +242,7 @@ describe("<Form />", () => {
const submitButton = screen.getByText("Preview");
await waitFor(() => expect(submitButton).toBeEnabled());
const estimateMock = jest.mocked(estimate);
estimateMock.mockRejectedValue(new Error("Some error occurred"));
estimateMock.mockRejectedValue(new CustomError("Some error occurred"));

await act(() => user.click(submitButton));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
} from "@umami/state";
import { executeParams } from "@umami/test-utils";
import { mockImplicitAddress } from "@umami/tezos";
import { CustomError } from "@umami/utils";

import { FormPage, type FormValues } from "./FormPage";
import { SignPage } from "./SignPage";
Expand Down Expand Up @@ -98,7 +99,7 @@ describe("<Form />", () => {
);

const estimateMock = jest.mocked(estimate);
estimateMock.mockRejectedValue(new Error("Some error occurred"));
estimateMock.mockRejectedValue(new CustomError("Some error occurred"));

const submitButton = screen.getByText("Preview");
await waitFor(() => expect(submitButton).toBeEnabled());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { estimate, makeAccountOperations, mockImplicitAccount } from "@umami/cor
import { type UmamiStore, WalletClient, addTestAccount, makeStore, mockToast } from "@umami/state";
import { executeParams } from "@umami/test-utils";
import { mockImplicitAddress } from "@umami/tezos";
import { CustomError } from "@umami/utils";

import { useHandleBeaconMessage } from "./useHandleBeaconMessage";
import { BatchSignPage } from "../../components/SendFlow/Beacon/BatchSignPage";
Expand Down Expand Up @@ -251,7 +252,7 @@ describe("<useHandleBeaconMessage />", () => {
});

it("doesn't open a modal on an error while estimating the fee", async () => {
jest.mocked(estimate).mockRejectedValueOnce(new Error("Something went very wrong!"));
jest.mocked(estimate).mockRejectedValueOnce(new CustomError("Something went very wrong!"));

const message: BeaconRequestOutputMessage = {
type: BeaconMessageType.OperationRequest,
Expand Down
3 changes: 2 additions & 1 deletion apps/desktop/src/views/batch/BatchView.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
} from "@umami/core";
import { type UmamiStore, addTestAccount, makeStore, mockToast } from "@umami/state";
import { executeParams } from "@umami/test-utils";
import { CustomError } from "@umami/utils";

import { BatchView } from "./BatchView";
import { act, render, screen, userEvent, within } from "../../mocks/testUtils";
Expand Down Expand Up @@ -85,7 +86,7 @@ describe("<BatchView />", () => {

it("doesn't show up if the estimation fails with an unknown error", async () => {
const user = userEvent.setup();
jest.mocked(estimate).mockRejectedValue(new Error("something went wrong"));
jest.mocked(estimate).mockRejectedValue(new CustomError("something went wrong"));

render(<BatchView operations={operations} />, { store });

Expand Down
6 changes: 3 additions & 3 deletions apps/web/src/components/SendFlow/Delegation/FormPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
mockToast,
} from "@umami/state";
import { executeParams } from "@umami/test-utils";
import { CustomError } from "@umami/utils";

import { FormPage, type FormValues } from "./FormPage";
import { SignPage } from "./SignPage";
Expand Down Expand Up @@ -112,14 +113,13 @@ describe("<Form />", () => {
});

const estimateMock = jest.mocked(estimate);
estimateMock.mockRejectedValue(new Error("Some error occurred"));
estimateMock.mockRejectedValue(new CustomError("Some error occurred"));

await act(() => user.click(submitButton));

expect(estimateMock).toHaveBeenCalledTimes(1);
expect(mockToast).toHaveBeenCalledWith({
description:
"Something went wrong. Please try again or contact support if the issue persists.",
description: "Some error occurred",
status: "error",
isClosable: true,
});
Expand Down
6 changes: 3 additions & 3 deletions apps/web/src/components/SendFlow/Tez/FormPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
} from "@umami/core";
import { type UmamiStore, addTestAccount, makeStore, mockToast } from "@umami/state";
import { executeParams } from "@umami/test-utils";
import { CustomError } from "@umami/utils";

import { FormPage } from "./FormPage";
import { SignPage } from "./SignPage";
Expand Down Expand Up @@ -167,14 +168,13 @@ describe("<Form />", () => {
const submitButton = screen.getByText("Preview");
await waitFor(() => expect(submitButton).toBeEnabled());
const estimateMock = jest.mocked(estimate);
estimateMock.mockRejectedValue(new Error("Some error occurred"));
estimateMock.mockRejectedValue(new CustomError("Some error occurred"));

await act(() => user.click(submitButton));

expect(estimateMock).toHaveBeenCalledTimes(1);
expect(mockToast).toHaveBeenCalledWith({
description:
"Something went wrong. Please try again or contact support if the issue persists.",
description: "Some error occurred",
status: "error",
isClosable: true,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
} from "@umami/state";
import { executeParams } from "@umami/test-utils";
import { mockImplicitAddress } from "@umami/tezos";
import { CustomError } from "@umami/utils";

import { FormPage, type FormValues } from "./FormPage";
import { SignPage } from "./SignPage";
Expand Down Expand Up @@ -93,7 +94,7 @@ describe("<Form />", () => {
);

const estimateMock = jest.mocked(estimate);
estimateMock.mockRejectedValue(new Error("Some error occurred"));
estimateMock.mockRejectedValue(new CustomError("Some error occurred"));

const submitButton = screen.getByText("Preview");
await waitFor(() => expect(submitButton).toBeEnabled());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { estimate, makeAccountOperations, mockImplicitAccount } from "@umami/cor
import { type UmamiStore, WalletClient, addTestAccount, makeStore, mockToast } from "@umami/state";
import { executeParams } from "@umami/test-utils";
import { mockImplicitAddress } from "@umami/tezos";
import { CustomError } from "@umami/utils";

import { useHandleBeaconMessage } from "./useHandleBeaconMessage";
import { BatchSignPage } from "../../components/SendFlow/Beacon/BatchSignPage";
Expand Down Expand Up @@ -251,7 +252,7 @@ describe("<useHandleBeaconMessage />", () => {
});

it("doesn't open a modal on an error while estimating the fee", async () => {
jest.mocked(estimate).mockRejectedValueOnce(new Error("Something went very wrong!"));
jest.mocked(estimate).mockRejectedValueOnce(new CustomError("Something went very wrong!"));

const message: BeaconRequestOutputMessage = {
type: BeaconMessageType.OperationRequest,
Expand Down
2 changes: 1 addition & 1 deletion packages/tezos/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,6 @@ export const decryptSecretKey = async (secretKey: string, password: string) => {
throw new CustomError("Invalid secret key: checksum doesn't match");
}

throw error;
throw new CustomError(error.message);
}
};

1 comment on commit 013b870

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Title Lines Statements Branches Functions
apps/desktop Coverage: 83%
83.88% (1764/2103) 79.35% (838/1056) 78.45% (448/571)
apps/web Coverage: 83%
83.88% (1764/2103) 79.35% (838/1056) 78.45% (448/571)
packages/components Coverage: 97%
97.51% (196/201) 95.91% (94/98) 88.13% (52/59)
packages/core Coverage: 81%
82.47% (207/251) 72.72% (88/121) 81.35% (48/59)
packages/crypto Coverage: 100%
100% (43/43) 90.9% (10/11) 100% (7/7)
packages/data-polling Coverage: 97%
95.27% (141/148) 87.5% (21/24) 92.85% (39/42)
packages/multisig Coverage: 98%
98.47% (129/131) 85.71% (18/21) 100% (36/36)
packages/social-auth Coverage: 100%
100% (21/21) 100% (11/11) 100% (3/3)
packages/state Coverage: 85%
84.78% (819/966) 80.86% (186/230) 78.59% (301/383)
packages/tezos Coverage: 89%
88.72% (118/133) 94.59% (35/37) 86.84% (33/38)
packages/tzkt Coverage: 89%
87.32% (62/71) 87.5% (14/16) 80.48% (33/41)

Please sign in to comment.