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

Improve error handling when smart contract is not found #586

Merged
merged 15 commits into from
Feb 17, 2024

Conversation

ymekuria
Copy link
Collaborator

@ymekuria ymekuria commented Feb 16, 2024

Description

Closes #329

Previously when an error occurred while importing a smart contract from the build directory during the deploy step, the zkApp CLI would swallow the error and display the message.

  Failed to find the "Add" smart contract in your build directory.
  Please confirm that your config.json contains the name of the smart contract that you desire to deploy to this deploy alias.

There are many different errors that can happen while importing a smart contract. This caused a poor DX, and made it extremely hard for user to find the source of the real errors.

Solution

This PR improves the error handling for zk deploy when a smart contract is not found in the build directory. A custom error message is only shown to a user if the smart contract is not found in the build directory. All other errors are thrown otherwise, enabling users to identify the cause of the error.

Additionaly, the custom error message was improved to help a user troubleshoot the problem when a contract is not found in the build directory.

…actImports before throwing error to provide more specific error message
…ract in build directory

The error message displayed when failing to find the specified smart contract in the build directory was not clear enough. This commit improves the error message by providing more detailed instructions to the user. The error message now asks the user to confirm that their config.json file contains the name of the smart contract they want to deploy to the specified alias. Additionally, it reminds the user to check that they have exported their smart contract class using a named export.
…art contract is not found in build directory
…ot found in build directory and propogate node error otherwise.

The previous implementation of importing the smart contract class to deploy from the user's file was complex and difficult to understand. This commit refactors the logic to improve readability and error handling.

- The variable `smartContractImports` is now declared and assigned directly in the try block, removing the need for a separate declaration outside the try block.
- The import path for the smart contract file is now constructed before the try block, simplifying the code.
- The error handling for importing the smart contract class has been improved. If the named export is not found, an error message is logged and the process exits with a non-zero status code.

These changes make the code more maintainable and easier to understand.
Copy link
Member

@shimkiv shimkiv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with comment.

@ymekuria ymekuria merged commit 4649a67 into main Feb 17, 2024
12 checks passed
@ymekuria ymekuria deleted the feature/contract-import-error-handeling branch February 17, 2024 21:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve error handling when imported smart contract is not found
2 participants