fix(go-client): resolve errors from runtime metadata instead of hardcoded list#1086
Open
sameh-farouk wants to merge 1 commit intodevelopmentfrom
Open
fix(go-client): resolve errors from runtime metadata instead of hardcoded list#1086sameh-farouk wants to merge 1 commit intodevelopmentfrom
sameh-farouk wants to merge 1 commit intodevelopmentfrom
Conversation
…oded list Replace the static moduleErrors/tfgridModuleErrors/smartContractModuleErrors/ tftBridgeModuleErrors arrays with a single call to metadata.FindError(). The hardcoded lists required manual updates after every runtime upgrade that added, removed, or reordered pallet errors. Missing entries caused the client to return unhelpful "unknown code" messages instead of the actual error name. The runtime metadata (V14+) already contains all pallet error definitions. The go-substrate-rpc-client library provides FindError(moduleIndex, errorIndex) which resolves to the error variant name from metadata at connect time. This is not a breaking change — the public API still returns error with the same error name strings (e.g. "NodeHasRentContract"). The only difference is the source: metadata instead of a static array. Fixes #778
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 0 |
| Duplication | -17 |
TIP This summary will be updated as you push new changes. Give us feedback
Member
Author
|
Tested |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replace the hardcoded error lists (281 lines) with a single
metadata.FindError()call that resolves error names from the runtime metadata at connect time.Problem
The Go client maintained three static arrays (
tfgridModuleErrors,smartContractModuleErrors,tftBridgeModuleErrors) mapping module/error indices to human-readable names. Every runtime upgrade that added, removed, or reordered pallet errors required a manual client update. Missing entries produced unhelpful messages:Fix
The
go-substrate-rpc-clientlibrary already providesMetadata.FindError(moduleIndex, errorIndex)which reads error definitions from runtime metadata V14+. This resolves error names automatically, no client update needed when pallets errors change or new errors introduced.Not a breaking change
The public API still returns
errorwith the same error name strings (e.g."NodeHasRentContract"). The only difference is the source: runtime metadata instead of a static array.Changes
clients/tfchain-client-go/utils.go: removed 281 lines of hardcoded error lists, replacedcheckForErrorwith metadata-based lookup (11 lines)Fixes #778