Move.

Post

Share your knowledge.

Jackson.
Nov 16, 2023
Expert Q&A

Handling Standard Errors in Sui Framework: Best Practices and Recommendations?

While exploring the implementation of standard errors, I noticed that the Sui repository utilizes the original move std error locally, stored as a part of an external crate (external-crates/move/move-stdlib/sources/error.move). However, I encountered an issue with using this external crate alongside the Sui module stored in (crates/sui-framework/packages/sui-framework/Move.toml) due to a dependency conflict. Upon comparing this with Aptos, I observed that Aptos provides an API for the error module, requiring users to use AptosFramework (aptos-move/framework/aptos-framework/Move.toml). However, the error Move module itself is present in move-stdlib (aptos-move/framework/move-stdlib/sources/error.move). This contrasted with Sui, where the error module seems to be absent in the move-stdlib directory (crates/sui-framework/packages/move-stdlib/sources/error.move is missing). My question is, is there a recommended or equivalent method for marking specific errors as actual standard errors that can be utilized in a multi-module environment within the Sui framework?

  • Move CLI
1
2
Share
Comments
.

Answers

2
Steven.
Nov 16 2023, 13:40

In the context of the Sui framework, it's a convention to keep constants and errors local to Move module (s) rather than importing them from other Move package (s). Unlike some other frameworks like Aptos, Sui does not create a separate error Move module. When working with Sui, it is recommended to define your error constants and handling functions within the specific module where they are used, avoiding imports from external packages. This convention helps maintain a clear and encapsulated structure within modules, ensuring a consistent approach to error handling. If you are creating packages that depend on each other, consider organizing error constants and handling functions within the modules where they are relevant, adhering to the Sui convention of localizing constants and errors. This approach aligns with the framework's design principles and ensures a cohesive codebase within the Sui ecosystem.

0
Comments
.
Jeremy.
Nov 16 2023, 13:46

In the Sui framework, the error handling mechanism seems to be different from Aptos. Aptos provides an API for the error Move module and requires users to use the AptosFramework, which includes the error module. However, in Sui, the error module seems to be missing from the move-stdlib directory.

Given this, if you want to mark specific errors as standard errors in a multi-module environment within the Sui framework, you may need to create your own error handling module. This module would define the standard errors that your application needs and provide a way to throw and handle these errors.

Here's a basic example of how you might define an error handling Move module:

module ErrorHandling {
   public fun standard_error(message: vector<u8>) {
       // Implement your error handling logic here
   }
}

In this example, standard_error is a public function that takes a message as a parameter. You can call this function whenever you want to throw a standard error.

You would also need to create a way to handle these errors. This could be done in the same module or in a separate module. Here's an example of how you might handle errors:

module ErrorHandling {
   public fun standard_error(message: vector<u8>) {
       // Implement your error handling logic here
   }

   public fun handle_error(error: vector<u8>) {
       // Implement your error handling logic here
   }
}

In this example, handle_error is a public function that takes an error as a parameter. You can call this function whenever you want to handle an error.

0
Comments
.

Do you know the answer?

Please log in and share it.

Move is an executable bytecode language used to implement custom transactions and smart contracts.

148Posts231Answers
Sui.X.Peera.

Earn Your Share of 1000 Sui

Gain Reputation Points & Get Rewards for Helping the Sui Community Grow.

Reward CampaignJune
We use cookies to ensure you get the best experience on our website.
More info