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

Cannot read properties of undefined (reading 'toHuman') #5875

Closed
7 tasks
ioannist opened this issue May 10, 2024 · 4 comments · Fixed by #5879
Closed
7 tasks

Cannot read properties of undefined (reading 'toHuman') #5875

ioannist opened this issue May 10, 2024 · 4 comments · Fixed by #5879

Comments

@ioannist
Copy link

ioannist commented May 10, 2024

  • I'm submitting a bug
  • [ x] Bug report
  • Feature request
  • Support request
  • Other
  • What is the current behavior and expected behavior?

for events and extrinsics:
GenericExtrinsic<AnyTuple> EventRecord.event: Event
calling
e.toJSON()
works fine

calling
e.toHuman()

 error: Error: Error in processBlockRange pipe: Error: Error in fetchBlockData: TypeError: Cannot read properties of undefined (reading 'toHuman')
      at file:///root/stakexyz-worker/indexer-activities/src/indexer.ts:138:48
      at Observable.init [as _subscribe] (/root/stakexyz-worker/indexer-activities/node_modules/rxjs/dist/cjs/internal/observable/throwError.js:8:64)
      at Observable._trySubscribe (/root/stakexyz-worker/indexer-activities/node_modules/rxjs/dist/cjs/internal/Observable.js:41:25)
      at /root/stakexyz-worker/indexer-activities/node_modules/rxjs/dist/cjs/internal/Observable.js:35:31
      at Object.errorContext (/root/stakexyz-worker/indexer-activities/node_modules/rxjs/dist/cjs/internal/util/errorContext.js:22:9)
      at Observable.subscribe (/root/stakexyz-worker/indexer-activities/node_modules/rxjs/dist/cjs/internal/Observable.js:26:24)
      at /root/stakexyz-worker/indexer-activities/node_modules/rxjs/dist/cjs/internal/operators/catchError.js:17:31
      at OperatorSubscriber._this._error (/root/stakexyz-worker/indexer-activities/node_modules/rxjs/dist/cjs/internal/operators/OperatorSubscriber.js:43:21)
      at Subscriber.error (/root/stakexyz-worker/indexer-activities/node_modules/rxjs/dist/cjs/internal/Subscriber.js:60:18)
      at Subscriber._error (/root/stakexyz-worker/indexer-activities/node_modules/rxjs/dist/cjs/internal/Subscriber.js:84:30)
      at Subscriber.error (/root/stakexyz-worker/indexer-activities/node_modules/rxjs/dist/cjs/internal/Subscriber.js:60:18)
      at Subscriber._error (/root/stakexyz-worker/indexer-activities/node_modules/rxjs/dist/cjs/internal/Subscriber.js:84:30)
      at Subscriber.error (/root/stakexyz-worker/indexer-activities/node_modules/rxjs/dist/cjs/internal/Subscriber.js:60:18)
      at Subscriber._error (/root/stakexyz-worker/indexer-activities/node_modules/rxjs/dist/cjs/internal/Subscriber.js:84:30)
      at Subscriber.error (/root/stakexyz-worker/indexer-activities/node_modules/rxjs/dist/cjs/internal/Subscriber.js:60:18)
      at Subscriber._error (/root/stakexyz-worker/indexer-activities/node_modules/rxjs/dist/cjs/internal/Subscriber.js:84:30),
  durationMs: 1673
}

This used to work in v10.11.2 and i think it broke in 10.13.1

  • Version:

  • Environment:

    • [x ] Node.js
    • Browser
    • Other (limited support for other environments)
  • Language:

    • JavaScript
    • [ x] TypeScript (node18)
    • Other
@TarikGul
Copy link
Member

Can you provide a reproducible example, that would help a lot with narrowing this down.

@ioannist
Copy link
Author

Can you provide a reproducible example, that would help a lot with narrowing this down.

import { ApiPromise, WsProvider } from "@polkadot/api";
import { Vec } from "@polkadot/types";
import { EventRecord } from "@polkadot/types/interfaces";

(async () => {
  try {
    console.log('Results to-> TypeError: Cannot read properties of undefined (reading \'toHuman\') in >=10.13.1')

    const provider = new WsProvider('wss://moonbeam.unitedbloc.com');
    const api = await ApiPromise.create({ provider, throwOnConnect: true });

    for (let blockNumber = 1000000; blockNumber < 1001000; blockNumber++) {
      const hash = await api.rpc.chain.getBlockHash(blockNumber);
      const apiAt = await api.at(hash);

      const allRecords = await apiAt.query.system.events() as Vec<EventRecord>;

      for (const record of allRecords) {
        record.event.toHuman()
      }

      const signedBlock = await api.rpc.chain.getBlock(hash);


      for (let extrinsicIndex = 0; extrinsicIndex < signedBlock.block.extrinsics.length; extrinsicIndex++) {
        const extrinsic = signedBlock.block.extrinsics[extrinsicIndex];
        extrinsic.toHuman()
      }
    }
  } catch (err) {
    console.error(err)
    throw err;
  }
})();

@TarikGul
Copy link
Member

Fix will be included in Mondays release

@polkadot-js-bot
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue if you think you have a related problem or query.

@polkadot-js polkadot-js locked as resolved and limited conversation to collaborators May 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants