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

Adds better error messages for FlowStakingCollection and ledger transactions #455

Merged
merged 5 commits into from
Oct 17, 2024

Conversation

joshuahannan
Copy link
Member

@joshuahannan joshuahannan commented Oct 15, 2024

Updates all the transactions and their dependencies that we use for ledger devices to use more descriptive error messages.

I decided to put some constructors for common error messages in the contract so we didn't have to hard code them in every transaction. I think I would like to start following this pattern from now on for other contracts. I'm open to suggestions on how they should work and be formatted, so please let me know if you have any feedback.


if let machineAccount = self.stakingCollectionRef.createMachineAccountForExistingNode(nodeID: nodeID, payer: account) {
let sigAlgo = SignatureAlgorithm(rawValue: machineAccountKeySignatureAlgorithm)
?? panic("Could not get a signature algorithm from the raw enum value provided")
?? panic("Cannot create machine account with provided key: Must provide a signature algorithm raw value that corresponds to "
Copy link
Member Author

Choose a reason for hiding this comment

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

I think I do want to put this error message construction in a contract somewhere. Any ideas about where it could go? Potentially in the Crypto contract? Or maybe just in the Service Account contract? Another option would be to create a new contract in the service account that just contains multiple different common error message constructions.

Copy link
Member

Choose a reason for hiding this comment

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

At first glance, the Crypto contract makes the most sense to me. A version of the enum constructor that panics on invalid input with an error message like this.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree, Crypto makes the most sense, maybe adding a getter for these enums which reverts with the appropriate message

Copy link
Member Author

Choose a reason for hiding this comment

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

@joshuahannan joshuahannan changed the title Adds better error messages for ledger transactions Adds better error messages for FlowStakingCollection and ledger transactions Oct 16, 2024
contracts/FlowStakingCollection.cdc Outdated Show resolved Hide resolved

if let machineAccount = self.stakingCollectionRef.createMachineAccountForExistingNode(nodeID: nodeID, payer: account) {
let sigAlgo = SignatureAlgorithm(rawValue: machineAccountKeySignatureAlgorithm)
?? panic("Could not get a signature algorithm from the raw enum value provided")
?? panic("Cannot create machine account with provided key: Must provide a signature algorithm raw value that corresponds to "
Copy link
Member

Choose a reason for hiding this comment

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

At first glance, the Crypto contract makes the most sense to me. A version of the enum constructor that panics on invalid input with an error message like this.

Copy link
Contributor

@sisyphusSmiling sisyphusSmiling left a comment

Choose a reason for hiding this comment

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

Great error messages!

contracts/FlowStakingCollection.cdc Outdated Show resolved Hide resolved
contracts/FlowStakingCollection.cdc Outdated Show resolved Hide resolved
contracts/FlowStakingCollection.cdc Outdated Show resolved Hide resolved
contracts/FlowStakingCollection.cdc Outdated Show resolved Hide resolved

if let machineAccount = self.stakingCollectionRef.createMachineAccountForExistingNode(nodeID: nodeID, payer: account) {
let sigAlgo = SignatureAlgorithm(rawValue: machineAccountKeySignatureAlgorithm)
?? panic("Could not get a signature algorithm from the raw enum value provided")
?? panic("Cannot create machine account with provided key: Must provide a signature algorithm raw value that corresponds to "
Copy link
Contributor

Choose a reason for hiding this comment

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

I agree, Crypto makes the most sense, maybe adding a getter for these enums which reverts with the appropriate message

@joshuahannan joshuahannan merged commit 44e80f4 into master Oct 17, 2024
2 checks passed
@joshuahannan joshuahannan deleted the ledger-error-msgs branch October 17, 2024 16:09
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.

3 participants