Skip to content

Commit

Permalink
Improve error handling when smart contract is not found (#586)
Browse files Browse the repository at this point in the history
  • Loading branch information
ymekuria authored Feb 17, 2024
1 parent 0d85e23 commit 4649a67
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,18 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

## Unreleased

### Changed

- Improve error handling when imported smart contract is not found. [#586](https://github.com/o1-labs/zkapp-cli/pull/586)

## [0.17.1](https://github.com/o1-labs/zkapp-cli/compare/v17.0...v17.1) - 2024-02-17

### Changed

- Improve error handling for zk deploy when feepayer has insufficient permissions. [#580](https://github.com/o1-labs/zkapp-cli/pull/580)
- Update `getCachedFeepayerAliases()` logic to prevent edge case bugs. [#581](https://github.com/o1-labs/zkapp-cli/pull/581)

- Improve error handling for zk deploy when fee payer has insufficient permissions. [#580](https://github.com/o1-labs/zkapp-cli/pull/580)

- Automate "zk config" if Lightnet is in use. [#579](https://github.com/o1-labs/zkapp-cli/pull/579)
- The `--lightnet` option was added to `zk config` in order to automatically configures zkApp project's deploy aliases.
- The [Lightnet](https://docs.minaprotocol.com/zkapps/testing-zkapps-lightnet) should be up and running before executing the `zk config --lightnet` command.
Expand Down
25 changes: 7 additions & 18 deletions src/lib/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,29 +239,18 @@ export async function deploy({ alias, yes }) {
contractName
);

let smartContractImports;
try {
let smartContractImportPath = `${projectRoot}/build/src/${smartContractFile}`;
if (process.platform === 'win32') {
smartContractImportPath = 'file://' + smartContractImportPath;
}
smartContractImports = await import(smartContractImportPath);
} catch (_) {
log(
chalk.red(
` Failed to find the "${contractName}" smart contract in your build directory.\n Please confirm that your config.json contains the name of the smart contract that you want to deploy to this deploy alias.`
)
);

process.exit(1);
let smartContractImportPath = `${projectRoot}/build/src/${smartContractFile}`;
if (process.platform === 'win32') {
smartContractImportPath = 'file://' + smartContractImportPath;
}

// Attempt to import the smart contract class to deploy from the user's file.
const smartContractImports = await import(smartContractImportPath);

// If we cannot find the named export log an error message and return early.
if (!(contractName in smartContractImports)) {
if (smartContractImports && !(contractName in smartContractImports)) {
log(
chalk.red(
` Failed to find the "${contractName}" smart contract in your build directory.\n Check that you have exported your smart contract class using a named export and try again.`
` Failed to find the "${contractName}" smart contract in your build directory.\n Please confirm that your config.json contains the name of the smart \n contract that you want to deploy using this deploy alias, check that\n you have exported your smart contract class using a named export and try again.`
)
);

Expand Down

0 comments on commit 4649a67

Please sign in to comment.