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

Provide a better error message when an unknown error occurs in deployment #304

Merged
merged 3 commits into from
Nov 14, 2022

Conversation

MartinMinkov
Copy link
Contributor

Description

Addresses #255 when a deployment fails with an error response that is not in the form we expect. When a GraphQL error occurs, we expect an array of errors to be returned from the endpoint we are issuing. When an error returns that's not an array, an unhelpful message is shown along the lines of:

zk deploy 
✔ Build project
✔ Generate build.json
✔ Choose smart contract
  The 'Square' smart contract will be used
  for this network as specified in config.json.
✔ Generate verification key (takes 10-30 sec)
  Using the cached verification key
✔ Build transaction
✔ Send to network
zk deploy [alias]

Deploy or redeploy a zkApp

Options:
  -y, --yes      Respond `yes` to all confirmation prompts.
                 Allows running non-interactively within a script.     [boolean]
  -h, --help     Show help                                             [boolean]
  -v, --version  Show version number                                   [boolean]

TypeError: errors.map is not a function
    at getErrorMessage (/usr/lib/node_modules/zkapp-cli/src/lib/deploy.js:569:12)
    at deploy (/usr/lib/node_modules/zkapp-cli/src/lib/deploy.js:422:13)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Object.handler (/usr/lib/node_modules/zkapp-cli/src/bin/index.js:80:21)

This PR makes a change to log Failed to send transaction. Unknown error if such an error occurs instead.

Copy link
Contributor

@mitschabaude mitschabaude left a comment

Choose a reason for hiding this comment

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

lgtm, one question though

@@ -419,7 +419,7 @@ async function deploy({ alias, yes }) {

if (!txn || txn?.kind === 'error') {
// Note that the thrown error object is already console logged via step().
log(red(getErrorMessage(txn.message ?? [])));
log(red(getErrorMessage(txn?.message ?? [])));
Copy link
Contributor

Choose a reason for hiding this comment

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

this is an improvement, but I wonder if there's additional benefit in also looking at the statusCode and statusText (see what sendGraphQL returns) for potential info if the txn.message is not an array of errors. Also, I wonder if there could be more info in the responseJson

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good point! Should we just dump the returned json if they are no array of errors to report on? On one hand, giving an Unknown error message is better than a runtime error but I would like to have more traceability in errors when they do occur.

Copy link
Contributor

@jasongitmail jasongitmail left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Collaborator

@ymekuria ymekuria left a comment

Choose a reason for hiding this comment

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

LGTM!Thanks for adding this!

@bkase
Copy link
Member

bkase commented Nov 14, 2022

We think logging the malformed error to the console is a good idea

Use the util.format built-in to format the error receieved inside
getErrorMessage(). This gives us better logging and discoverability when
an unknown error occurs. By using util.format, we get the message and
stack properties in the log output.
@MartinMinkov MartinMinkov merged commit e10b6ef into main Nov 14, 2022
@MartinMinkov MartinMinkov deleted the feat/deployment-error-msg branch November 14, 2022 20:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants