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: better errors text for WalletConnect #2308

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
20 changes: 20 additions & 0 deletions packages/utils/src/ErrorContext.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@ describe("getErrorContext", () => {
expect(context.timestamp).toBeDefined();
});

it("should handle Error instances with unknown Tezos-specific errors", () => {
const error = new Error("protocol.unknown.error");

const context = getErrorContext(error);

expect(context.technicalDetails).toBe("protocol.unknown.error");
expect(context.description).toBe(
"Tezos blockchain rejected the transaction: protocol.unknown.error. Please try again or contact support if the issue persists."
);
expect(context.stacktrace).toBeDefined();
expect(context.timestamp).toBeDefined();
});

it("should handle CustomError instances", () => {
const error = new CustomError("Custom error message");

Expand Down Expand Up @@ -93,6 +106,13 @@ describe("handleTezError", () => {
expect(res).toBe("The delegate is unchanged. Delegation to this address is already done.");
});

it("catches contract.manager.unregistered_delegate", () => {
const res = handleTezError(new Error("contract.manager.unregistered_delegate"));
expect(res).toBe(
"The provided delegate address is not registered as a delegate. Verify the delegate address and ensure it is active."
);
});

it("returns undefined for unknown errors", () => {
const err = new Error("unknown error");
expect(handleTezError(err)).toBeUndefined();
Expand Down
6 changes: 5 additions & 1 deletion packages/utils/src/ErrorContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export const handleTezError = (err: Error): string | undefined => {
return "Emptying an implicit delegated account is not allowed. End delegation before trying again.";
} else if (err.message.includes("delegate.unchanged")) {
return "The delegate is unchanged. Delegation to this address is already done.";
} else if (err.message.includes("contract.manager.unregistered_delegate")) {
return "The provided delegate address is not registered as a delegate. Verify the delegate address and ensure it is active.";
}
};

Expand All @@ -59,7 +61,9 @@ export const getErrorContext = (error: any): ErrorContext => {
description = error.message;
technicalDetails = "";
} else if (error instanceof Error) {
description = handleTezError(error) ?? description;
description =
handleTezError(error) ||
`Tezos blockchain rejected the transaction: ${error.message}. Please try again or contact support if the issue persists.`;
}

return {
Expand Down
Loading