Skip to content
This repository has been archived by the owner on Sep 5, 2023. It is now read-only.

Error message when starknet-class-hash command do not work as expected #908

Merged
80 changes: 42 additions & 38 deletions src/starknetCli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
StarkNetNewAccountOptions,
} from './cli';
import { CLIError, logError } from './utils/errors';
import { runStarkNetClassHash } from './utils/utils';
import { getPersonalizedStarknetError, runStarkNetClassHash } from './utils/utils';
import { encodeInputs } from './transcode/encode';
import { decodeOutputs } from './transcode/decode';
import { decodedOutputsToString } from './transcode/utils';
Expand Down Expand Up @@ -53,23 +53,18 @@ export function compileCairo(
]
.map(([key, value]) => `--${key} ${value}`)
.join(' ')}`,
{ stdio: 'inherit' },
);

return { success: true, resultPath, abiPath, solAbiPath, classHash: undefined };
} catch (e) {
if (e instanceof Error) {
logError('Compile failed');
return {
success: false,
resultPath: undefined,
abiPath: undefined,
solAbiPath: undefined,
classHash: undefined,
};
} else {
throw e;
}
} catch (e: any) {
const error = getPersonalizedStarknetError('starknet-compile', e.stderr.toString());
logError(error);
return {
success: false,
resultPath: undefined,
abiPath: undefined,
solAbiPath: undefined,
classHash: undefined,
};
}
}

Expand All @@ -96,14 +91,16 @@ export function runStarknetStatus(tx_hash: string, option: IOptionalNetwork & IG
: '';

try {
execSync(
const output = execSync(
`${warpVenvPrefix} starknet tx_status --hash ${tx_hash} --network ${option.network} ${gatewayUrlOption} ${feederGatewayUrlOption}`.trim(),
{
stdio: 'inherit',
encoding: 'utf8',
},
);
} catch {
logError('starknet tx_status failed');
console.log(output);
} catch (e: any) {
const error = getPersonalizedStarknetError('starknet tx_status', e.stderr.toString());
logError(error);
}
}

Expand Down Expand Up @@ -159,7 +156,7 @@ export async function runStarknetDeploy(filePath: string, options: IDeployProps)
const accountDirOption = options.account_dir ? `--account_dir ${options.account_dir}` : '';
const maxFeeOption = options.max_fee ? `--max_fee ${options.max_fee}` : '';
const resultPath = compileResult.resultPath;
execSync(
const output = execSync(
`${warpVenvPrefix} starknet deploy --network ${options.network} ${
options.no_wallet
? `--no_wallet --contract ${resultPath} `
Expand All @@ -170,11 +167,13 @@ export async function runStarknetDeploy(filePath: string, options: IDeployProps)
options.account !== undefined ? `--account ${options.account}` : ''
} ${gatewayUrlOption} ${feederGatewayUrlOption} ${accountDirOption} ${maxFeeOption}`,
{
stdio: 'inherit',
encoding: 'utf8',
},
);
} catch {
logError('starknet deploy failed');
console.log(output);
} catch (e: any) {
const error = getPersonalizedStarknetError('starknet deploy', e.stderr.toString());
logError(error);
}
}

Expand All @@ -195,7 +194,7 @@ export function runStarknetDeployAccount(options: IDeployAccountProps) {
const account = options.account ? `--account ${options.account}` : '';

try {
execSync(
const output = execSync(
`${warpVenvPrefix} starknet deploy_account --wallet ${options.wallet} --network ${
options.network
} ${account} ${options.gateway_url ? `--gateway_url ${options.gateway_url}` : ''} ${
Expand All @@ -204,11 +203,13 @@ export function runStarknetDeployAccount(options: IDeployAccountProps) {
options.max_fee ? `--max_fee ${options.max_fee}` : ''
}`,
{
stdio: 'inherit',
encoding: 'utf8',
},
);
} catch {
logError('starknet deploy failed');
console.log(output);
} catch (e: any) {
const error = getPersonalizedStarknetError('starknet deploy_account', e.stderr.toString());
logError(error);
}
}

Expand Down Expand Up @@ -272,8 +273,9 @@ export async function runStarknetCallOrInvoke(
warpOutput = decodedOutputsToString(decodedOutputs);
}
console.log(warpOutput);
} catch {
logError(`starknet ${callOrInvoke} failed`);
} catch (e: any) {
const error = getPersonalizedStarknetError(`starknet ${callOrInvoke}`, e.stderr.toString());
logError(error);
}
}

Expand Down Expand Up @@ -310,15 +312,16 @@ function declareContract(filePath: string, options: IDeclareOptions) {
const maxFeeOption = options.max_fee ? `--max_fee ${options.max_fee}` : '';

try {
execSync(
const output = execSync(
`${warpVenvPrefix} starknet declare --contract ${filePath} ${networkOption} ${walletOption} ${accountOption} ${gatewayUrlOption} ${feederGatewayUrlOption} ${accountDirOption} ${maxFeeOption}`,
{
stdio: 'inherit',
encoding: 'utf8',
},
);
} catch {
logError('Starknet declare failed');
console.log(output);
} catch (e: any) {
const error = getPersonalizedStarknetError('starknet declare', e.stderr.toString());
logError(error);
}
}

Expand All @@ -344,15 +347,16 @@ export function runStarknetNewAccount(options: StarkNetNewAccountOptions) {
: '';
const accountDirOption = options.account_dir ? `--account_dir ${options.account_dir}` : '';
try {
execSync(
const output = execSync(
`${warpVenvPrefix} starknet new_account ${networkOption} ${walletOption} ${accountOption} ${gatewayUrlOption} ${feederGatewayUrlOption} ${accountDirOption}`,
{
stdio: 'inherit',
encoding: 'utf8',
},
);
} catch {
logError('Starknet new account creation failed');
console.log(output);
} catch (e: any) {
const error = getPersonalizedStarknetError('starknet new_account', e.stderr.toString());
logError(error);
}
AlejandroLabourdette marked this conversation as resolved.
Show resolved Hide resolved
}

Expand Down
2 changes: 1 addition & 1 deletion src/utils/setupVenv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function runVenvSetup(options: IInstallOptions) {
execSync(`${warpVenv} ${options.python}`, { stdio: options.verbose ? 'inherit' : 'pipe' });
} catch {
logError(
'Try using --python option for warp install and specify the path to python3.7 e.g "warp install --python /usr/bin/python3.7"',
'Try using --python option for warp install and specify the path to python3.9 e.g "warp install --python /usr/bin/python3.9"',
);
}
}
18 changes: 14 additions & 4 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -541,11 +541,21 @@ export function getSourceFromLocations(
export function runStarkNetClassHash(filePath: string): string {
const warpVenvPrefix = `PATH=${path.resolve(__dirname, '..', '..', 'warp_venv', 'bin')}:$PATH`;

const classHash = execSync(`${warpVenvPrefix} starknet-class-hash ${filePath}`).toString().trim();
if (classHash === undefined) {
throw new Error(`starknet-class-hash failed`);
try {
return execSync(`${warpVenvPrefix} starknet-class-hash ${filePath}`).toString().trim();
} catch (e: any) {
AlejandroLabourdette marked this conversation as resolved.
Show resolved Hide resolved
const error = getPersonalizedStarknetError('starknet-class-hash', e.stderr.toString());
throw new TranspileFailedError(error);
}
return classHash;
}

export function getPersonalizedStarknetError(starknetCommand: string, err: string) {
AlejandroLabourdette marked this conversation as resolved.
Show resolved Hide resolved
if (err.includes('command not found')) {
return `'${starknetCommand}' command not found.
Please make sure you are using the required version of starknet by executing 'warp install' command.
See more about it using 'warp install --help'.`;
}
return err;
}

export function getContainingFunction(node: ASTNode): FunctionDefinition {
Expand Down