Missing undefined check in JavaScript SDK

The txns property is {} in several blocks (e.g. 329923). Calling:
let block = await algodClient.block(i);

Results in the following error:
TypeError: Cannot read property 'length' of undefined in algod.js.

Suggested fix is to check for this case before getting the upper limit of the for loop:
if (res.statusCode === 200 && typeof res.body.txns.transactions !== "undefined") {

Sincerely,
Jimmy

2 Likes

Great catch Jimmy. I will update the example.

I meant to say we will update the source. Thanks for finding this.

Cool and there are other functions that might need the same.
Just curious, what is special/different about these blocks?

As a side note, since I have your ear. I cannot roll up a release of an CLI app that incorporates the Go SDK using ‘dep’ because algorand/go-codec is still private on Github. I see the source in the vendor/ subdirectory. However since it’s a dependency in the SDK’s Gopkg.toml, then ‘dep’ dies. I’m not sure what enhancements you’ve made over ugorji/go-codec, hopefully you’ll consider releasing it.

Cheers,
Jimmy

Jimmy,

All transaction loops will need be checked like that. That is a block with no transactions.
On the Go SDK packaging, I am checking on this.

Jimmy,

go-codec should now be public. Can you let us know if this worked?

Worked on the first try! Thanks for that.

Jimmy