Skip to content

Commit

Permalink
Converted hex errors to readable errors
Browse files Browse the repository at this point in the history
  • Loading branch information
acheroncrypto committed Apr 21, 2022
1 parent b469896 commit c45e8a7
Show file tree
Hide file tree
Showing 15 changed files with 71 additions and 22 deletions.
2 changes: 1 addition & 1 deletion client/src/components/Foldable/Foldable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from "react";
import styled from "styled-components";

import { ClassNames } from "../../constants/";
import { ClassNames } from "../../constants";
import { Arrow } from "../Icons";

interface FoldableProps {
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/Input/Input.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { FocusEvent } from "react";
import styled, { css } from "styled-components";

import { ClassNames } from "../../constants/";
import { ClassNames } from "../../constants";

interface InputProps {
fullWidth?: boolean;
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/Panels/Bottom/Bottom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ConnState } from "../Side/Right/Wallet/connection-states";
import Link from "../../Link";
import useCurrentWallet from "../Side/Right/Wallet/useCurrentWallet";
import useConnect from "../Side/Right/Wallet/useConnect";
import { NETWORKS } from "../../../constants/connection";
import { NETWORKS } from "../../../constants";

const Bottom = () => {
const { connection: conn } = useConnection();
Expand Down
4 changes: 3 additions & 1 deletion client/src/components/Panels/Side/Right/Deploy/Deploy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { PgProgramInfo } from "../../../../../utils/pg/program-info";
import { terminalAtom } from "../../../../../state";
import { pgWalletAtom, refreshPgWalletAtom } from "../../../../../state/solana";
import Text from "../../../../Text";
import { PgError } from "../../../../../utils/pg/error";

const Deploy = () => {
const [pgWallet] = useAtom(pgWalletAtom);
Expand Down Expand Up @@ -41,7 +42,8 @@ const Deploy = () => {

msg = "Deployment successful";
} catch (e: any) {
msg = `Deployment error: ${e.message}`;
const convertedError = PgError.convertErrorMessage(e.message);
msg = `Deployment error: ${convertedError}`;
} finally {
setTerminal(msg);
setLoading(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import styled from "styled-components";
import { explorerAtom, refreshExplorerAtom } from "../../../../../state";
import { Arrow } from "../../../../Icons";
import ContextMenu from "./ContextMenu";
import { ClassNames } from "../../../../../constants/";
import { ClassNames } from "../../../../../constants";
import LangIcon from "../../../../LangIcon";
import { PgExplorer } from "../../../../../utils/pg/explorer";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { ctxSelectedAtom, modalAtom, newItemAtom } from "../../../../../state";
import { PgExplorer } from "../../../../../utils/pg/explorer";
import RenameItem from "./RenameItem";
import DeleteItem from "./DeleteItem";
import { ClassNames } from "../../../../../constants/";
import { ClassNames } from "../../../../../constants";

interface MenuState {
show: boolean;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useAtom } from "jotai";
import { ChangeEvent, useCallback, useMemo } from "react";

import { NETWORKS } from "../../../../../constants/connection";
import { NETWORKS } from "../../../../../constants";
import { endpointAtom } from "../../../../../state/solana";
import { PgEndpoint } from "../../../../../utils/pg/endpoint";
import Select from "../../../../Select";
Expand Down
6 changes: 4 additions & 2 deletions client/src/components/Panels/Side/Right/Test/Function.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ import Arg from "./Arg";
import { getFullType } from "./types";
import { PgTest } from "../../../../../utils/pg/test";
import { updateTxValsProps } from "./useUpdateTxVals";
import { ClassNames } from "../../../../../constants/";
import { ClassNames } from "../../../../../constants";
import { terminalAtom } from "../../../../../state";
import useCurrentWallet from "../Wallet/useCurrentWallet";
import { PgTx } from "../../../../../utils/pg/tx";
import { PgError } from "../../../../../utils/pg/error";

type KV = {
[key: string]: string | number | BN | PublicKey | Signer;
Expand Down Expand Up @@ -151,7 +152,8 @@ const Function: FC<FunctionProps> = ({ ixs, idl, index }) => {
() => (msg = `Test '${ixs.name}' passed. Tx hash: ${txHash}`)
);
} catch (e: any) {
msg = `Test '${ixs.name}' error: ${e.message}`;
const convertedError = PgError.convertErrorMessage(e.message);
msg = `Test '${ixs.name}' error: ${convertedError}`;
} finally {
setTerminal(msg);
setLoading(false);
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/Panels/Side/Right/Wallet/Wallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Button from "../../../../Button";
import useConnect from "./useConnect";
import useCurrentWallet from "./useCurrentWallet";
import { endpointAtom } from "../../../../../state/solana";
import { Endpoints } from "../../../../../constants/connection";
import { Endpoints } from "../../../../../constants";

const Wallet = () => {
const [, setTerminal] = useAtom(terminalAtom);
Expand Down
31 changes: 31 additions & 0 deletions client/src/constants/errors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
export enum ItemError {
ALREADY_EXISTS = "Already exists",
INVALID_NAME = "Invalid name",
}

interface ProgramError {
[key: string]: string;
}

export const PROGRAM_ERROR: ProgramError = {
"0": "Lamport balance below rent-exempt threshold",
"1": "Insufficient funds",
"2": "Invalid Mint(token address)",
"3": "Account not associated with this Mint(token address)",
"4": "Owner does not match",
"5": "This token's supply is fixed and new tokens cannot be minted.",
"6": "The account cannot be initialized because it is already being used.",
"7": "Invalid number of provided signers",
"8": "Invalid number of required signers",
"9": "State is unititialized",
a: "Instruction does not support native tokens",
b: "Non-native account can only be closed if its balance is zero",
c: "Invalid instruction",
d: "State is invalid for requested operation.",
e: "Operation overflowed",
f: "Account does not support specified authority type",
"10": "This token mint cannot freeze accounts",
"11": "Account is frozen, all account operations will fail",
"12": "The provided decimals value different from the Mint decimals",
"13": "Instruction does not support non-native tokens",
};
2 changes: 2 additions & 0 deletions client/src/constants/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export * from "./connection";
export * from "./html-class";
export * from "./project";
export * from "./img";
export * from "./errors";
2 changes: 1 addition & 1 deletion client/src/utils/pg/endpoint.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Endpoints } from "../../constants/connection";
import { Endpoints } from "../../constants";

const ENDPOINT_KEY = "endpoint";

Expand Down
17 changes: 17 additions & 0 deletions client/src/utils/pg/error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { PROGRAM_ERROR } from "../../constants";

export class PgError {
static convertErrorMessage(msg: string) {
for (const programErrorCode in PROGRAM_ERROR) {
if (msg.endsWith(programErrorCode)) {
msg = msg.replace(
`custom program error: 0x${programErrorCode}`,
PROGRAM_ERROR[programErrorCode]
);
break;
}
}

return msg;
}
}
4 changes: 0 additions & 4 deletions client/src/utils/pg/errors.ts

This file was deleted.

13 changes: 6 additions & 7 deletions client/src/utils/pg/explorer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ClassNames } from "../../constants/";
import { ItemError } from "./errors";
import { ClassNames, ItemError } from "../../constants";

const EXPLORER_KEY = "explorer";

Expand Down Expand Up @@ -95,12 +94,12 @@ export class Explorer {
newItem(fullPath: string) {
// Invalid name
if (!PgExplorer.isItemNameValid(PgExplorer.getItemNameFromPath(fullPath)!))
return { err: ItemError.InvalidName };
return { err: ItemError.INVALID_NAME };

const files = this._explorer.files;

// Already exists
if (files[fullPath]) return { err: ItemError.AlreadyExists };
if (files[fullPath]) return { err: ItemError.ALREADY_EXISTS };

const itemType = PgExplorer.getItemTypeFromPath(fullPath);

Expand Down Expand Up @@ -143,7 +142,7 @@ export class Explorer {

renameItem(fullPath: string, newName: string) {
if (!PgExplorer.isItemNameValid(newName))
return { err: ItemError.InvalidName };
return { err: ItemError.INVALID_NAME };

const files = this._explorer.files;

Expand All @@ -154,7 +153,7 @@ export class Explorer {
const parentFolder = PgExplorer.getParentPathFromPath(fullPath);
const newPath = parentFolder + newName;

if (files[newPath]) return { err: ItemError.AlreadyExists };
if (files[newPath]) return { err: ItemError.ALREADY_EXISTS };

// Store the file
const file = files[fullPath];
Expand Down Expand Up @@ -183,7 +182,7 @@ export class Explorer {
}

// Check if newPath exists
if (files[newPath]) return { err: ItemError.AlreadyExists };
if (files[newPath]) return { err: ItemError.ALREADY_EXISTS };

// Store the data
const data = files[path];
Expand Down

0 comments on commit c45e8a7

Please sign in to comment.