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

Decide what to do with Cosmos-SDK errors #2802

Open
aljo242 opened this issue Sep 1, 2022 · 10 comments
Open

Decide what to do with Cosmos-SDK errors #2802

aljo242 opened this issue Sep 1, 2022 · 10 comments
Labels
component:scaffold Feature, enhancement, or refactor related to scaffolding.

Comments

@aljo242
Copy link
Contributor

aljo242 commented Sep 1, 2022

The defined error types (such as ErrInsufficientFunds) still exist under the cosmos/cosmos-sdk path.

@aljo242 What's the reason behind this separation between error functions and error definitions ? I find easier to have everything in the same package.

The main reasoning is that the package has been deprecated. The new package is located here and does not contain the registered error types.

I also agree that separating packages is not ideal. According to this note, chains should be registering their own errors. I'm not sure what to do with this, so maybe we should have a broader discussion.

Originally posted by @aljo242 in #2794 (comment)

@aljo242
Copy link
Contributor Author

aljo242 commented Sep 1, 2022

In summary, cosmos-sdk has moved their errors package, only keeping the functionality - no defined error types are included. It seems like their recommendation is for chains to define all the errors themselves in appropriate codespaces.

We need to move to the cosmossdk.io/errors package (because the other is deprecated), but the current solution I have in #2794 is certainly not ideal.

We could:

  1. keep things as I have them in refactor: use cosmossdk.io/errors package #2794
  2. Have chains define all of the errors in a package that is scaffolded in them
  3. Create a package in cli that registers the errors in the "cosmos-sdk" subspace and have chains import this
  4. Create a new repo ignite/sdk-errors that registers the errors in the "cosmos-sdk" subspace and have chains import this

I think the best solution is 4, but let me know what y'all think.

@aljo242 aljo242 self-assigned this Sep 1, 2022
@aljo242
Copy link
Contributor Author

aljo242 commented Sep 1, 2022

Another option is that we do nothing for the time being, but it does look like the plan is to remove the old types/errors package at some point.

@tbruyelle
Copy link
Contributor

  1. keep things as I have them in refactor: use cosmossdk.io/errors package #2794

We'll have to do something at some point, so let's do it now since we have the time.

  1. Have chains define all of the errors in a package that is scaffolded in them

This is my preferred solution. The current types/errors/errors.go is copied in a CLI template and scaffolded in any new chain.

  • this follows the recommandation "chains should define their own errors"
  • it allows the user to add/customize those errors
  1. Create a package in cli that registers the errors in the "cosmos-sdk" subspace and have chains import this

Let's not add more CLI dependencies in scaffolded chain :P

  1. Create a new repo ignite/sdk-errors that registers the errors in the "cosmos-sdk" subspace and have chains import this

Better than 3)


That being said, for the moment, the cosmos-sdk doesn't follow that recommandation since those errors are still used in many places in their codebase. In addition there's some protocol-oriented errors like ErrTxInMempoolCache, what will they do with them ? It's definitely not an error that should be defined in a chain.

So to conclude I'm not sure we have sufficient information about the future of those errors to be able to take the right decision.

@aljo242
Copy link
Contributor Author

aljo242 commented Sep 1, 2022

That being said, for the moment, the cosmos-sdk doesn't follow that recommandation since those errors are still used in many places in their codebase. In addition there's some protocol-oriented errors like ErrTxInMempoolCache, what will they do with them ? It's definitely not an error that should be defined in a chain.

So to conclude I'm not sure we have sufficient information about the future of those errors to be able to take the right decision.

Yeah, this is confusing to me. There are many "top level" errors that make sense to be defined in an "sdk" codespace since they sort of apply globally to Cosmos SDK chains.

@aljo242
Copy link
Contributor Author

aljo242 commented Sep 1, 2022

Option 2 sounds good to me, but how should and where we add these definitions to chains?

We also use the sdk error types ourselves in cli so we will need to register our own errors for those as well.

@lumtis
Copy link
Contributor

lumtis commented Sep 1, 2022

Option 3 sounds good to me, but how should and where we add these definitions to chains?
We also use the sdk error types ourselves in cli so we will need to register our own errors for those as well.

This is a good solution. Not sure neither why those have been removed in the new package since something like invalidAddress is quite general.

Referring to chains should be registering their own errors we should rather go with solution 2 but we should avoid being unnecessarily too verbose in the scaffolding.

From the PR you created ignite/modules#38 using this package in the templates looks like a good solution to me as ignite/module will intend to provide many utilities for SDK development. Developers are free to define their own error afterward. Scaffolding commands are not final, scaffolded code is aimed to be modified by developers afterward

@aljo242
Copy link
Contributor Author

aljo242 commented Sep 2, 2022

@lubtd do you mean having scaffolded chains import ignite/modules/errors package?

@lumtis
Copy link
Contributor

lumtis commented Sep 2, 2022

Yes, the other way would be to generate a package error general for the chain like we do with testutil but I'm not a big fan generating folder in user repo

@aljo242 aljo242 mentioned this issue Sep 2, 2022
7 tasks
@ilgooz
Copy link
Member

ilgooz commented Sep 3, 2022

I would say a combo of 2 and 3, where 3 is for common errors and 2 is for chain specific errors.

@aljo242 aljo242 added component:scaffold Feature, enhancement, or refactor related to scaffolding. priority/low and removed priority/low labels Oct 27, 2022
@tac0turtle
Copy link
Contributor

app chains should define their own code space and use those instead of the sdk. It is some extra boilerplate but helps in debug ability.

Please don't provide them a package to import, this goes against what the sdk is trying to establish

@aljo242 aljo242 removed their assignment Dec 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component:scaffold Feature, enhancement, or refactor related to scaffolding.
Projects
None yet
Development

No branches or pull requests

5 participants