Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix custom error handling #2210

Merged
merged 2 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
};
Loading