Skip to content

fix(go-client): resolve errors from runtime metadata instead of hardcoded list#1086

Open
sameh-farouk wants to merge 1 commit intodevelopmentfrom
fix/go-client-metadata-errors
Open

fix(go-client): resolve errors from runtime metadata instead of hardcoded list#1086
sameh-farouk wants to merge 1 commit intodevelopmentfrom
fix/go-client-metadata-errors

Conversation

@sameh-farouk
Copy link
Copy Markdown
Member

@sameh-farouk sameh-farouk commented Apr 9, 2026

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:

module error (26) with unknown code [23 0 0 0] occurred, please update the module error list

Fix

The go-substrate-rpc-client library already provides Metadata.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 error with 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, replaced checkForError with metadata-based lookup (11 lines)

Fixes #778

…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
@sameh-farouk sameh-farouk requested a review from LeeSmet as a code owner April 9, 2026 13:33
@codacy-production
Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · -17 duplication

Metric Results
Complexity 0
Duplication -17

View in Codacy

TIP This summary will be updated as you push new changes. Give us feedback

@sameh-farouk
Copy link
Copy Markdown
Member Author

Tested

{"level":"debug","url":"wss://tfchain.dev.grid.tf/ws","time":"2026-04-09T15:55:29+02:00","message":"connecting"}
2026/04/09 15:55:29 Connecting to wss://tfchain.dev.grid.tf/ws...
Connected to wss://tfchain.dev.grid.tf/ws
Account: 5DFkH2fcqYecVHjfgAEfxgsJyoEg5Kd93JFihfpHDaNoWagJ
Twin ID: 41

--- Test 1: Create farm with duplicate name ---
  Error: failed to create farm: FarmExists
  PASS: Got pallet error 'FarmExists' from metadata

--- Test 2: Cancel contract we don't own ---
  Error: failed to cancel contract: ContractNotExists
  PASS: Got pallet error 'ContractNotExists' from metadata

--- Test 3: Create duplicate name contract ---
  Created name contract 264770, trying duplicate...
  Error: failed to create contract: NameExists
  PASS: Got pallet error 'NameExists' from metadata

  Cleaning up: canceling test contract...
--- Test 4: Rent non-existent node ---
  Error: failed to create rent contract: NodeNotExists
  PASS: Got pallet error 'NodeNotExists' from metadata


=== Results: 4 passed, 0 failed ===

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.

Client(go): read errors from meta

1 participant